These are the commands which modify a string. Note that none of these modify the string in place. In all cases a new string is returned.
- string- tolower- string
- Returns stringwith all the letters converted from upper to lower case.
- string- toupper- string
- Returns stringwith all the letters converted from lower to upper case.
- string- trim- string- ?trimChars?
- Returns stringwith all occurrences oftrimCharsremoved from both ends. By defaulttrimCharsare whitespace (spaces, tabs, newlines). Note that the characters are not treated as a "block" of characters - in other words,string trim "davidw" dwwould return the stringaviand notdavi.
- string- trimleft- string- ?trimChars?
- Returns stringwith all occurrences oftrimCharsremoved from the left. By defaulttrimCharsare whitespace (spaces, tabs, newlines)
- string- trimright- string- ?trimChars?
- Returns stringwith all occurrences oftrimCharsremoved from the right. By defaulttrimCharsare whitespace (spaces, tabs, newlines)
- format- formatString- ?arg1 arg2 ... argN?
- Returns a string formatted in the same manner as the ANSIsprintfprocedure.FormatStringis a description of the formatting to use. The full definition of this protocol is in theformatman page. A useful subset of the definition is thatformatStringconsists of literal words, backslash sequences, and% fields. The% fieldsare strings which start with a%and end with one of:- s... Data is a string
- d... Data is a decimal integer
- x... Data is a hexadecimal integer
- o... Data is an octal integer
- f... Data is a floating point number
 The%may be followed by:- -... Left justify the data in this field
- +... Right justify the data in this field
 The justification value may be followed by a number giving the minimum number of spaces to use for the data.
Example
set upper "THIS IS A STRING IN UPPER CASE LETTERS"
set lower "this is a string in lower case letters"
t leader "....This string has leading dots"
set
set trailer "This string has trailing dots ...."
s
eboth "((this string is nested in parens )))"
puts "tolower converts this: $upper"
$lower"
puts " to this: [string toupper $l
puts " to this: [string tolower $upper]\n"
puts "toupper converts this:
ower]\n"
puts "trimright converts this: $trailer"
puts " to this: [string trimright $trailer .]\n"
erts this: $both"
puts " to
puts "trimleft converts this: $leader"
puts " to this: [string trimleft $leader .]\n"
puts "trim con
vthis: [string trim $both "()"]\n"
set labels [format "%-20s %+10s " "Item" "Cost"]
set price1 [format "%-20s %10d Cents Each" "Tomatoes" "30"]
0.2f per Lb." "Steak" "3.59997"]
puts "\n Example of form
set price2 [format "%-20s %10d Cents Each" "Peppers" "20"]
set price3 [format "%-20s %10d Cents Each" "Onions" "10"]
set price4 [format "%-20s %
1at:\n"
puts "$labels"
puts "$price1"
puts "$price2"
puts "$price3"
puts "$price4"

 
 
0 Comment:
Post a Comment