user2131316
user2131316

Reputation: 3267

how to combine two strings in TCL?

I have the following code in 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"

Upvotes: 4

Views: 23699

Answers (3)

Terry
Terry

Reputation: 1007

Use the append command:

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

Upvotes: 1

Jerry
Jerry

Reputation: 71538

You can use append like this:

% 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...

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

Upvotes: 8

user414441
user414441

Reputation:

String concatenation in tcl is just juxtaposition

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

Upvotes: 6

Related Questions