Jun 15, 2005 #1 Ati2ude Programmer Dec 11, 2001 79 US I would like to parse this string into mulitple strings or a list. set string "MYSTRINGTOPARSE" first = "MY" second = "STRING" third = "TO" fourth = "PARSE" etc... Any pointers would be great, as always thanks in advance. Brian
I would like to parse this string into mulitple strings or a list. set string "MYSTRINGTOPARSE" first = "MY" second = "STRING" third = "TO" fourth = "PARSE" etc... Any pointers would be great, as always thanks in advance. Brian
Jun 15, 2005 #2 Bong Programmer Dec 22, 1999 2,063 US If you know the lengths you can use regexp as follows: regexp {(\w{2})(\w{6})(\w{2})(\w{5})} $string match first second third forth _________________ Bob Rashkin rrashkin@csc.com Upvote 0 Downvote
If you know the lengths you can use regexp as follows: regexp {(\w{2})(\w{6})(\w{2})(\w{5})} $string match first second third forth _________________ Bob Rashkin rrashkin@csc.com
Jun 16, 2005 #3 cptk Technical User Mar 18, 2003 305 US Like BONG suggested, in your example you must know the lengths of the expected string since you have no delimitors in your initial string. That said, let's assume you do have some kind of a delimitor (e.g. - " ").... set string "MY STRING TO PARSE" set n 0 ### Set-up a variable array - va(1), va(2), etc. foreach x $string { set va($n) $x incr n } ### display each value of the array for {set i 0} {$i < $n} {incr i} { puts $va($i) } ### and just to demostrate the names of array puts [array names va] OUTPUT: my string to parse 0 1 2 3 ...hope that helps!! Upvote 0 Downvote
Like BONG suggested, in your example you must know the lengths of the expected string since you have no delimitors in your initial string. That said, let's assume you do have some kind of a delimitor (e.g. - " ").... set string "MY STRING TO PARSE" set n 0 ### Set-up a variable array - va(1), va(2), etc. foreach x $string { set va($n) $x incr n } ### display each value of the array for {set i 0} {$i < $n} {incr i} { puts $va($i) } ### and just to demostrate the names of array puts [array names va] OUTPUT: my string to parse 0 1 2 3 ...hope that helps!!