如何在TCL中组合两个字符串?

时间:2013-08-07 14:47:07

标签: string tcl

我在tcl中有以下代码:

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

如何将两个字符串组合成"do the firstthing do the secondthing"

3 个答案:

答案 0 :(得分:6)

您可以像这样使用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

答案 1 :(得分:5)

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

set result "$string1$string2"
set result $string1$string

答案 2 :(得分:1)

使用append命令:

set string1 "do the firstthing"
set string2 "do the secondthing"
append var $string1 "," $string2
puts $var
# Prints do the firstthing,do the secondthing