TCL : Concatenate a variable and a string

tcl
user651006 picture user651006 · Mar 9, 2011 · Viewed 52k times · Source

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..

Answer

Trey Jackson picture Trey Jackson · Mar 9, 2011

You can do:

set b ${a}9876

or, assuming b is either set to the empty string or not defined:

append b $a 9876

The call to append is more efficient when $a is long (see append doc).