Assume we have a variable 'a' set to 12345 :
set a 12345
Now how do i set a new variable 'b' which contains the value of 'a' and another string say 9876
workaround is something like
set a "12345"
set u "9876"
set b $a$u
but i dont want to specify $u
instead i want the direct string to used..
other option is to use set command. since set a gives value of a we can use it to set value of b like below
set b [set a]9876
You can do:
or, assuming
b
is either set to the empty string or not defined:The call to
append
is more efficient when$a
is long (seeappend
doc).set myString "Hello"
append myString " World!"
puts "$myString"
Hello World!
I don't get what you mean the direct string... I'm not sure if you want... However, if you want the value of 12349876 you can do:
If you want $a or $u to be part of the string, just add a backslash '\' before the desired variable.
From Tcl 8.6.2 onwards, there is
string cat
which can be used to solve this problem.Other option is to use concat command like below.
set b [concat $a\9876]