我在 tcl 中有以下代码:
set string1 "do the firstthing"
set string2 "do the secondthing"
如何将两个字符串组合在一起"do the firstthing do the secondthing"
你可以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
tcl 中的字符串连接只是并列
set result "$string1$string2"
set result $string1$string
使用附加命令:
set string1 "do the firstthing"
set string2 "do the secondthing"
append var $string1 "," $string2
puts $var
# Prints do the firstthing,do the secondthing