How can I convert a known array in to string in TCL? an array might have values such as root_user_appversion 10.1.3.20 and/or I just want to take out the last values out of it which 10.1.3.20 .
-
At least show your effort what you have done.toxic_boi_8041– toxic_boi_80412016-03-19 08:38:38 +00:00Commented Mar 19, 2016 at 8:38
Add a comment
|
2 Answers
You can transform the array in list:
set my_list [array get my_array]
puts "last element: [lindex $my_list [expr {[llength $my_list] -1}] ]"
After that, you can easily convert your list in string with join:
set my_string [join $my_list " "]
2 Comments
Peter Lewerin
lindex $my_list end is more idiomatic.Peter Lewerin
Another problem with this is that it doesn't really solve the problem, it just stringifies the array contents.
I think you want
join [dict values [array get the_array]]
Which takes a list of alternating key / value items, filters out the value items, and joins them into a string.
Note that values with spaces will be munged: in that case you're better off with just dict values [array get the_array].