简体   繁体   English

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

[英]how to combine two strings in TCL?

I have the following code in tcl: 我在tcl中有以下代码:

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

how to make a combine two strings to have "do the firstthing do the secondthing" 如何组合两个字符串来"do the firstthing do the secondthing"

You can use append like this: 你可以像这样使用append

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

You can put them next to the other... 你可以把它们放在另一个旁边......

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

Or if your strings are in a list, you can use join and specify the connector... 或者如果您的字符串在列表中,您可以使用join并指定连接器...

% set listofstrings [list "do the firstthing" "do the secondthing"]
% puts [join $listofthings " "]
do the firstthing do the secondthing

String concatenation in tcl is just juxtaposition tcl中的字符串连接只是并置

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

Use the append command: 使用append命令:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM