簡體   English   中英

如何在TCL中組合兩個字符串?

[英]how to combine two strings in TCL?

我在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

使用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