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

use*_*316 2 string tcl

我在tcl中有以下代码:

set string1 "do the firstthing"
set string2 "do the secondthing"
Run Code Online (Sandbox Code Playgroud)

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

Jer*_*rry 6

你可以append像这样使用:

% set string1 "do the firstthing"
% set string2 "do the secondthing"
% append string1 " " $string2
% puts $string1
do the firstthing do the secondthing
Run Code Online (Sandbox Code Playgroud)

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

% set string1 "do the firstthing"
% set string2 "do the secondthing"
% puts "$string1 $string2"
do the firstthing do the secondthing
Run Code Online (Sandbox Code Playgroud)

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

% set listofstrings [list "do the firstthing" "do the secondthing"]
% puts [join $listofthings " "]
do the firstthing do the secondthing
Run Code Online (Sandbox Code Playgroud)


vrd*_*dhn 5

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

set result "$string1$string2"
set result $string1$string
Run Code Online (Sandbox Code Playgroud)