Reputation: 137
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
.
Upvotes: 0
Views: 2998
Reputation: 13252
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]
.
Documentation: array, dict, join
Upvotes: 0
Reputation: 9619
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 " "]
Upvotes: 4