A-A+
TCL中字符串的搜索
在TCL中通过命令stringfirst和string last进行字符串的搜索,使用方法如下:
string first th "There is the tubwhere I bathed today"
9
string first th "There is the tub where I bathed today" 12
27
string first在第二个字符串中搜索与第一个字符串相同的子字符串。如果找到,返回最左边的相同子字符串的开头字符的索引值;如果找不到,返回-1。如果不指定第三个参数,搜索从第二个字符串的开头字符开始,也可以通过第三个参数来指定开始搜索的字符的索引。
命令string last与stringfirst相似,只不过它返回的是最右边的相同子字符串的开头字符的索引值。例如:
string last th "There is the tub where I bathed today"
27
2 条留言 访客:1 条 博主:1 条