tags:

views:

154

answers:

3

How do I convert a list into string in Tcl?

A: 

Use the list command.

http://wiki.tcl.tk/440

Alternatively, see "split": http://wiki.tcl.tk/1499

split "comp.unix.misc"

returns "comp unix misc"

Martin Eve
You are giving ways to make a list from a string. The question asks for the opposite - how to get from list to string.
Colin Macleod
+10  A: 

most likely what you want is join however depending on what you are trying to do this may not be necessary.

anything in TCL is able to be treated as a string at anytime, consequently you may be able to just use your list as a string without explict conversion

jk
+2  A: 

If you just want the contents, you can puts $listvar and it will write out the contents as a string.

You can flatten the list by one level or insert a separator character by using join, as jk answered above.

Example:

% set a { 1 2 3 4 { 5 6 { 7 8 9 } } 10 }
 1 2 3 4 { 5 6 { 7 8 9 } } 10 
% puts $a
 1 2 3 4 { 5 6 { 7 8 9 } } 10 
% join $a ","
1,2,3,4, 5 6 { 7 8 9 } ,10
% join $a
1 2 3 4  5 6 { 7 8 9 }  10
Michael Mathews