I have a question regarding the string map command. What i understand so far: In general you have to set up pairs of words which are replaced by their counterparts. So in this example "not" and "script" is being replaced to "good" and "tcl script".
set mytext "i am a not working script"
set nword [string map -nocase {
"not" "good"
"script" "tcl script"
} $mytext];
putmsg $chan "$nword";
.. and so on
This example works fine. But if i try to insert string variables like lets say:
set string_one "not"
set string_two "good"
set nword [string map -nocase {
$string_one $string_two
} $mytext];
Well my noobish version does not work Manual pages says this:
Replaces substrings in string based on the key-value pairs in mapping. mapping is a list of key value key value ... as in the form returned by array get.
I tried some variations resulting in not replacing the string or in inbalance char maps. Can someone drop me a quick feedback how to solve this?
The reason why the second version does not work, is that you provide the two strings as separate arguments, whereas the documentation clearly specifies that string map expects <map> to be a (single argument) list with value pairs.
When you create lists using {} everything between the braces won't be evaluated, which means all Tcl commands and variables will be treated as normal strings or elements inside the list.
does the same thing (creates a list), but everything after
will be evaluated thus you can use variables and commands in it.