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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding a pattern in a comma seperated string

Status
Not open for further replies.

itzmesri

Programmer
Sep 7, 2009
5
GB
Hi,
Can anyone let me know how to find a pattern in a string which is comma seperated. With my limited knowledge of TCL, I figured out a way of doing it through the split command and compare each resulting string, however I do not wish to iterate so many times. Is there a shorter way of doing it.

S1 is "1,2,3,A,B,C" (I have a for each loop for this one)
S2 is "A,B,C,D,E,F,G"

I have a for each loop to pick up every individual elements in String S1, but I need a short cut (if there is one) to directly search for every value (of S1 picked up in the for loop) in S2 directly without having to loop through S2 one more time.

Any help would be highly appreciated.

Thanks,
 
If the search is for a string like "A,B,C" then you can search for that string. If on the other hand (and I think this is what you're asking) the search is for any of "A", "B", "C", then you have to use a loop.

There are other languages that have an "intersection" function but not Tcl (as far as I know).

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top