2013-08-07 47 views

回答

4

你可以使用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 
4

字符串連接僅僅是並列關係,

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

使用附加命令:

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

'append'命令具有不同的語義:您將* variable *作爲第一個參數,並將* values *作爲其他參數的變量列表。我編輯你的答案改變:你必須使用'$ string1'和'$ string2'來訪問這兩個變量的值,並把想要寫入的變量名。 –

+0

@MarcoPallante發表評論指出任何錯誤都很好,但如果他想編輯他的答案,則由特里決定。 – Stijn

+0

謝謝你的留言,@Stijn,下次我會做得更好:) –