0

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
  • At least show your effort what you have done. Commented Mar 19, 2016 at 8:38

2 Answers 2

4

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 " "]
Sign up to request clarification or add additional context in comments.

2 Comments

lindex $my_list end is more idiomatic.
Another problem with this is that it doesn't really solve the problem, it just stringifies the array contents.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.