[REBOL] Re: Splitting string based on substring separator
From: fuka:fuxoft:cz at: 22-Dec-2002 1:43
It doesn't help, see my previous post. It's string with binary data.
Andrew Martin wrote:
> Frantisek Fuka wrote:
>
>>Let's say I've got this string
>>
>>"HELLOsepP E O P L EsepHOWsepAREsepYOU"
>>
>>and I want to split it to substrings based on the separator string (in
>
> this case, "sep"). So I want this result:
>
>>["HELLO" "P E O P L E" "HOW" "ARE" "YOU"]
>>
>>I know I can do this using parse and build the resulting block
>
> programatically, but isn't there a simpler and cleaner solution? For
> example, if the separator was just one character long, I know I'd just
>
>>write:
>>
>>result: parse/all string-to-parse separator-character
>
> How about this:
>
>>>string-to-parse: "HELLOsepP E O P L EsepHOWsepAREsepYOU"
>
> == "HELLOsepP E O P L EsepHOWsepAREsepYOU"
>
>>>replace/all string-to-parse "sep" #"\"
>
> == "HELLO\P E O P L E\HOW\ARE\YOU"
>
>>>string-to-parse
>
> == "HELLO\P E O P L E\HOW\ARE\YOU"
>
>>>parse/all string-to-parse "\"
>
> == ["HELLO" "P E O P L E" "HOW" "ARE" "YOU"]
>
> Of couse this requires using a separator character that isn't used in the
> original string...
>
> I hope that helps!
>
> Andrew Martin
> ICQ: 26227169 http://valley.150m.com/
> -><-
>
--
Frantisek Fuka
(yes, that IS my real name)
(and it's pronounced "Fran-tjee-shek Foo-kah")
----------------------------------------------------
My E-mail: [fuka--fuxoft--cz]
My Homepage: http://www.fuxoft.cz
My ICQ: 2745855