(6)、string range string first last 与string index string charIndex类似,只不过他需要两个索引,返回的是first到last之间的字符串,如果fisrst小于0按0处理,last类似。 此外当字符串中含有空格等符号时需要使用””弱引用。 example: (7)、string replace string first last ?newstring? 字符替换与删除,如果first...
Example : set str "This is a string" puts "The string is: $str" puts "The length of the string is: [string length $str]" puts "The character at index 3 is: [string index $str 3]" puts "The characters from index 4 through 8 are: [string range $str 4 8]" puts "The index...
puts "The string is: $str" puts "The length of the string is: [string length $str]" puts "The character at index 3 is: [string index $str 3]" puts "The characters from index 4 through 8 are: [string range $str 4 8]" puts "The index of the first occurrence of letter \"i\...
string first "tcltk" "This is a tcltk example";#返回10,返回第一次匹配的索引,如果找不到则返回-1 string last "is" "This is a tcltk example";#返回5,返回最后一次匹配的索引 替换字符串 string map {key1 value1 key2 value3 ...} 1abcaababcabababc;#将1abcaababcabababc中的key1替换为val...
Example 8.1: set str "This is a string" puts "The string is: $str" puts "The length of the string is: [string length $str]" puts "The character at index 3 is: [string index $str 3]" puts "The characters from index 4 through 8 are: [string range $str 4 8]" ...
set fi [string range $fname 0 0] while {$fi=="+"} { puts $ntempop $line gets $nop line set fname [lindex $line 0] set fi [string range $fname 0 0] } } #如果不是不是我们要找的subckt,那就直接输入到临时文件中去 if {$flag==0} { ...
例子:018_string.tcl set string "this is my test string" puts "There are [string length $string] characters in \"$string\"" puts "[string index $string 1] is the second character in \"$string\"" ;#返回h puts "\"[string range $string 5 10]\" are characters between the 5'th an...
Example 1.3: set foo "puts hi" eval $foo Output: hi 在这个例子里,变量foo存储了另外一段Tcl script.表达式包括数学表达式,关系表达式,通常用 expr命令。 Example 2.1: expr 0 == 1 Output: 0 Example 2.2: expr 1 == 1 Output: 1 两数比较,true则输出1,false输出0 ...
puts [string index $str end] Thestring indexcommand returns the character at a specific position. puts [string range $str 1 3] Thestring rangereturns a range of characters selected by the first and last index. $ ./strings1.tcl 5
puts "The character at index 3 is: [string index $str 3]" puts "The characters from index 4 through 8 are: [string range $str 4 8]" puts "The index of the first occurrence of letter \"i\" is: [string first i $str]" 執行方法: ns ex7_1.tcl 執行的結果: The string is: This...