各文字列の単語を検索して以下のように変更する方法。置換の使い方
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
あなたがする必要があるのは、これらの2つのライブラリをstring map
で使用できるマップにアセンブルすることです。これの鍵は、foreach
という2つのリスト形式を使用でき、セパレータセットが空の場合はsplit
コマンドで文字列をコンポーネント文字に簡単に分割できます。
set map {}
foreach from [split $firstLibrary ""] to [split $secondLibrary ""] {
lappend map $from $to
}
$theString
にstring map
でマップを適用し、結果を印刷する運動として残っています。
その素晴らしい。もう1つ、文字列を2つの単語に分割する方法。例えば:{helloworlds}と出力は:he ll owまたはld s – Andre
@Andreそれはregexpのためのものです: 'regexp -all -inline {..?}" helloworlds "' –
最初の同じ文字列値の場合は2番目の文字列値を取得し、平均値は以下のように計算する方法。
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)を見てみましょうにドキュメント –