2

I need to parse through the array and find out a value at particular place in a TCL script

E.g., I have a string

set var "00 01 02 03"

I need to parse through the var to find what is there in the 3rd entry (02).

2 Answers 2

4

What you need is a TCL list. Remember the index counter starts at 0, so pass in 2 to lindex to find the 3rd element

% set my_list [list 00 01 02 03]
00 01 02 03
% lindex $my_list 2
02
Sign up to request clarification or add additional context in comments.

Comments

4

Your string can be interpreted as a list, so you could use lindex to get the 3rd list element (counted starting with index 0):

lindex $var 2

Better would be (and works with different delimiters, too):

lindex [split $var " "] 2

1 Comment

Sometimes, it is easier to use regexp -inline -all to do the word identification step.

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.