(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...
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...
The length of the string is: 16 The character at index 3 is: s The characters from index 4 through 8 are: is a The index of the first occurrence of letter "i" is: 2 eval 调用一个Tcl脚本 eval命令会把它的参数直接送往解释器。 Example 9.1: set foo "set a 22" eval $foo puts $a ...
puts "\"[string range $string 5 10]\" are characters between the 5'th and 10'th" ;#返回”is my ” 2.18 讲解: 1.字符串函数列表 序号 函数 解释 1 string compare string1 string2 字符串比较 返回: -1:string1比string2小 0:string1和string2相等 1:string1比string2大 2 string first str...
proc example {first {second ""} args} { ;#参数定义:赋缺省值和不确定个数参数定义 if {$second == ""} { puts "There is only one argument and it is: $first"; return 1; } else { if {$args == ""} { puts "There are two arguments - $first and $second"; ...
tcl> stringtrimright"xxabcxxxx" xxxabc tcl> stringtrimleft" a bc" a bc Here comes a small example that finds the word with 'x' in a sentence. tcl> set s {abc dexfgh ijklm} tcl> string first x $s 6 tcl> set start [stringwordstart$s 6] ;# start position ...
字符串是Tcl中最常用的类型,string有很多使用参数,可以参照Tcl手册。使用方法: string option arg arg ... 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...
string option arg arg ... 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: ...
-1:string1比string2小 :string1和string2相等 :string1比string2大 2 stringfirststring1string2 返回string1在string2中第一次出现的位置;如果string2不在string1中, 返回-1 3 stringlaststring1string2 返回string1在string2中最后一次出现的位置;如果string2不在string1 中,返回-1 4 stringwordstartstring1...
字符串是Tcl中最常用的类型,string有很多使用参数,可以参照Tcl手册。使用方法: string option arg arg ... Example 8.1: set str "This is a string" puts "The string is: $str" puts "The length of the string is: [string length $str]" ...