如何在Tcl中简洁地连接字符串? [英] How to concisely concatenate strings in Tcl?
问题描述
我可以很容易地在Tcl中将两个变量foo和bar连接起来: $ {foo} $ {bar}。
但是,如果我不这样做不想将中间结果放入变量中,我如何轻松地将调用proc的结果连接起来?
这应该写成长手:
set foo [myFoo $ arg]
set bar [myBar $ arg]
设置结果 $ {foo} $ {bar}
是否有某种方法可以创建结果而不引入临时变量foo和bar? / p>
这样做对我而言是不正确的:
concat [myFoo $ arg] [myBar $ arg]
因为它在两个结果之间引入了一个空格(用于列表目的)
好像是'string concat'就是我想要的,但是在我的Tcl解释器版本中似乎没有。
字符串concat [myFoo $ arg] [myBar $ arg]
字符串concat写在这里:
您可以将命令嵌入双引号中,而无需使用临时变量:
设置结果 [myFoo $ arg] [myBar $ arg]
I can easily concatenate two variables, foo and bar, as follows in Tcl: "${foo}${bar}".
However, if I don't want to put an intermediate result into a variable, how can I easily concatenate the results of calling some proc?
Long hand this would be written:
set foo [myFoo $arg]
set bar [myBar $arg]
set result "${foo}${bar}"
Is there some way to create result without introducing the temporary variables foo and bar?
Doing this is incorrect for my purposes:
concat [myFoo $arg] [myBar $arg]
as it introduces a space between the two results (for list purposes) if one does not exist.
Seems like 'string concat' would be what I want, but it does not appear to be in my version of Tcl interpreter.
string concat [myFoo $arg] [myBar $arg]
String concat is written about here:
You can embed commands within a double-quoted string without the need for a temporary variable:
set result "[myFoo $arg][myBar $arg]"
这篇关于如何在Tcl中简洁地连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!