Updated 2016-12-08 11:34:07 by foo

append appends strings to the value stored in a variable.

Synopsis  edit

append varName ?value value value ...?

Documentation  edit

official reference

Description  edit

Appends each value to the value stored in the variable named by varName. If varName doesn't exist, it is given a value equal to the concatenation of all the value arguments. This command provides an efficient way to build up long variables incrementally. For example, append a $b is much more efficient than set a $a$b, if $a is long.

append is a string command. When working with lists, definitely use concat or lappend.

Examples  edit

Building a string of comma-separated numbers piecemeal using a loop.
set var 0
for {set i 1} {$i <= 10} {incr i} {
    append var "," $i
}
puts $var
# Prints 0,1,2,3,4,5,6,7,8,9,10

See Also  edit

string
more string functions
concat
concatenate values.
lappend
append a word to a list