Array to string in TCL

妖精的绣舞 提交于 2021-02-08 11:48:19

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!