Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to return count of eleement in lindex

Status
Not open for further replies.

snowingnow

Programmer
Jun 1, 2006
32
0
0
CA
I use following script to reformate a string
..
set fieldo [split $segment |]
set field1 [lindex $fieldo 13]
set field2 [lindex $fieldo 14]

In field2, there may have some sub segments in it,some time only one, if have more than one then split by "^",
My question is how to i determine how many element in the field2, bascially i want to retrieve index of 0(first one) and 7(filed 8) if they have..
How can i do that?
Thanks


 
Hi

snowingnow said:
How to return count of eleement in lindex
Code:
puts "The list has [llength $fieldo] elements"
Or if you only want to know if there are one or more substrings, then check if the string contains the separator character. [tt]string first[/tt] will return -1 if the separator is not found.
Code:
string first "|" $segment
At least as I understood the subject. ( No idea what you asked in the question itself. )

Feherke.
 
Thank for the quick reponse..
You right i can use string first "^" $segment to determine if there are subsring in it, but i what to know how many substrings in it.. the reason i am asking is: let say if the string only contains 3 sub strings sperated by "^", i want a way to get max index number.. Thanks
 
The split command can have more than one delimiter characters specified. If you don't care about preserving the original "|" separation prior to the "^" separation, you can split on both at once:
Code:
split $segment {| ^}

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top