splitting difficult(?) strings [message #28758] |
Tue, 08 January 2002 09:33 |
hradilv.nospam
Messages: 19 Registered: November 2001
|
Junior Member |
|
|
Any ideas on what would be the easiest (best?) way to split strings
that have the following characteristics? Perhaps best understood by
looking at examples?
1)
buf= '4 5 6'
strsplit(buf,' ',/extract) yields ['4','5','6'] {good}
2)
buf = '"4" "5" "6"'
strsplit(buf,'" "',/extract) yields ['4','5','6'] {good}
3)
buf='"" "5" "6"' {should get ['','5','6']}
strsplit,buf,'" "',/extract) yields ['5','6'] {misses the empty one}
strsplit,buf,'"',/extract) yields [' ','5',' ','6'] {adds an extra
empty one}
4)
buf='"3 4" "5" "6"' {should get ['3 4','5','6'}
strsplit(buf,'" "',/extract) yields ['3','4','5','6'] {adds an extra
one}
strsplit(buf,'"',/extract) yields ['3 4',' ','5',' ','6'] {I can
always then get rid of the ' ' elements}
Maybe I can summarize: I would like something that will split the
string by spaces, PROTECTED by "s. ie there may be spaces within the
"s which should not cause a split.
Thanks in advance
Vince
|
|
|