3

我在 tcl 中有以下代码:

set string1 "do the firstthing"
set string2 "do the secondthing"

如何将两个字符串组合在一起"do the firstthing do the secondthing"

4

3 回答 3

7

你可以append这样使用:

% set string1 "do the firstthing"
% set string2 "do the secondthing"
% append string1 " " $string2
% puts $string1
do the firstthing do the secondthing

你可以把它们放在另一个旁边...

% set string1 "do the firstthing"
% set string2 "do the secondthing"
% puts "$string1 $string2"
do the firstthing do the secondthing

或者,如果您的字符串在列表中,您可以使用join并指定连接器...

% set listofstrings [list "do the firstthing" "do the secondthing"]
% puts [join $listofthings " "]
do the firstthing do the secondthing
于 2013-08-07T15:00:32.043 回答
6

tcl 中的字符串连接只是并列

set result "$string1$string2"
set result $string1$string
于 2013-08-07T14:49:27.373 回答
1

使用附加命令:

set string1 "do the firstthing"
set string2 "do the secondthing"
append var $string1 "," $string2
puts $var
# Prints do the firstthing,do the secondthing
于 2013-08-07T14:52:23.513 回答