简体   繁体   English

字符串串联,包括TCL中的变量

[英]String concatenation including variables in TCL

I am trying to accomplish something very simple in TCL. 我正在尝试在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 . 这导致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? 如何在没有那些中间空格的情况下将字符串与分配给TCL中变量的字符串连接起来?

You've got two options. 您有两个选择。 The classic Tcl way of doing things is this, with brace-delimited variable names: Tcl的经典处理方式是这样,用大括号分隔的变量名:

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): 从Tcl 8.6开始,还有命令string cat (被引入以使lmap更好地工作):

puts [string cat supercali $string1 expiali $string2]

Low-level behaviour should be identical. 低级行为应相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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