我可以轻松连接两个变量 foo 和 bar,如 Tcl 中所示:“${foo}${bar}”。
但是,如果我不想将中间结果放入变量中,如何轻松连接调用某个过程的结果?
长手这将被写成:
set foo [myFoo $arg]
set bar [myBar $arg]
set result "${foo}${bar}"
有没有某种方法可以在不引入临时变量 foo 和 bar 的情况下创建结果?
这样做对于我的目的来说是不正确的:
concat [myFoo $arg] [myBar $arg]
因为如果两个结果不存在,它会在两个结果之间引入一个空格(用于列表目的)。
看起来“字符串连接”就是我想要的,但它似乎不在我的 Tcl 解释器版本中。
string 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:
发布评论
评论(3)
您可以将命令嵌入双引号字符串中,而不需要临时变量:
You can embed commands within a double-quoted string without the need for a temporary variable:
如果您在循环中多次执行此操作,或由某些中间代码分隔,您还可以考虑:
If you are doing this many times, in a loop, or separated by some intermediate code, you might also consider:
只需将其写为没有多余空格的单词:
Tcl 在替换后将其视为单个单词,无论两个子命令的结果如何。
just write it as a word with no extra spaces:
Tcl sees this as a single word after substitution, regardless of the result of the two subcommands.