问题
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
.
回答1:
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:
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
来源:https://stackoverflow.com/questions/36081328/array-to-string-in-tcl