简体   繁体   中英

String concatenation including variables in TCL

I am trying to accomplish something very simple in TCL. Namely string concatenation where some (not all) of the strings are assigned to variables. For example

set string1 fragilistic
set string2 docious

puts [concat supercali $string1 expiali $string 2]

this results in supercali fragilistic expiali docious . I really dont want those spaces in between so what I tried to do was

puts [concat supercali$string1expiali$string 2]

But this will return an error. How can I concatenate strings with strings assigned to variables in TCL without those intermediate spaces?

You've got two options. The classic Tcl way of doing things is this, with brace-delimited variable names:

puts supercali${string1}expiali${string2}

From Tcl 8.6 onwards, there's also the command string cat (which was introduced to make lmap work better):

puts [string cat supercali $string1 expiali $string2]

Low-level behaviour should be identical.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM