comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: splitting difficult(?) strings
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: splitting difficult(?) strings [message #28748 is a reply to message #28737] Tue, 08 January 2002 14:49 Go to previous messageGo to previous message
Martin Downing is currently offline  Martin Downing
Messages: 136
Registered: September 1998
Senior Member
"Craig Markwardt" <craigmnet@cow.physics.wisc.edu> wrote in message
news:onr8p0k4se.fsf@cow.physics.wisc.edu...
>
> hradilv.nospam@yahoo.com writes:
>
>> 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}
> ...
>> 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.
>
> Using STRSPLIT is like sending a boy to do a man's job. I think there
> is no other choice but to hand-code what you want. [ Counter-examples
> welcomed. ] It *may* be possible to code it into a regular
> expression, but I'm not sure how to handle the "quotes-optional"
> aspect.
>

Hi Vince, this works for your examples:

---------------
FUNCTION vince_sep, s

IF strpos(s, '"') NE -1 THEN BEGIN
sa = strsplit(s, '^"|" "|"$', /EXTRACT,/REGEX, /PRESERVE_NULL)
n = n_elements(sa)
IF n GT 2 THEN sa = sa[1:n-2]
ENDIF ELSE BEGIN
sa = strsplit(s,' ', /EXTRACT)
ENDELSE
return, sa

END
-----------------



cheers

Martin
--
----------------------------------------
Martin Downing,
Clinical Research Physicist,
Grampian Orthopaedic RSA Research Centre,
Woodend Hospital, Aberdeen, AB15 6LS.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: IDl 5.3.1 on windows 2000
Next Topic: Re: IDL data coordinates in a widget

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 10:20:32 PDT 2025

Total time taken to generate the page: 0.72086 seconds