数组到 TCL 中的字符串 [英] Array to string in TCL
本文介绍了数组到 TCL 中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 TCL 中将已知数组转换为字符串?数组可能具有诸如 root_user_appversion 10.1.3.20
之类的值和/或我只想从中取出 10.1.3.20
的最后一个值.
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
.
推荐答案
你可以在列表中转换数组:
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}] ]"
之后,您可以使用 join
轻松地将列表转换为字符串:
After that, you can easily convert your list in string with join
:
set my_string [join $my_list " "]
这篇关于数组到 TCL 中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文