如何搜索每个字符串单词并将其更改为如下所示;如何使用替换
set firstLibrary {12345}
set secondLibrary {aghij}
备注:
1=a ; 2=g ; 3=h ; 4=i ; 5=j
set theString {44168}
然后输出; 44168 = iia68
如何搜索每个字符串单词并将其更改为如下所示;如何使用替换
set firstLibrary {12345}
set secondLibrary {aghij}
备注:
1=a ; 2=g ; 3=h ; 4=i ; 5=j
set theString {44168}
然后输出; 44168 = iia68
您需要做的是将这两个库组装成一个可与string map
一起使用的映射。关键在于你可以使用foreach
的双列表形式,并且如果分隔符集为空,则split
命令可以轻松地将字符串分解为其组成字符。
set map {}
foreach from [split $firstLibrary ""] to [split $secondLibrary ""] {
lappend map $from $to
}
应用与string map
地图上$theString
和打印结果留作练习。
其很好。还有,如何从sttring中分割一个字符串两个字。例如:{helloworlds}和输出结果如下:他将会运行或者ld s – Andre
@Andre这将是正则表达式的一部分:'regexp -all -inline {..?}“helloworlds” –
如何获得第二个字符串值,如果第一个相同的字符串值,然后计算平均值如下;
set first {A B B C D E E E E E G K}
set second {12 42 51 66 24 75 33 11 22 86 43 66}
set lenghtString [lenght $first]
for {set i 0} {$i < $lenghtString} {incr i} {
#arg please
#If same string on first string then get second string
#B B = (42+51)/2 = 46.5
#E E E E E = (75+33+11+22+86)/5 = 45.4
}
output with puts by rows: 12 46.5 66 24 45.4 86 66
这个问题不清楚,请添加更多细节 – georoot
看看[字符串映射(http://www.tcl.tk/man/tcl8.6/TclCmd/string.htm#M34)在文档 –