[REBOL] Re: Parse question
From: andreas:bolka:gmx at: 26-Jul-2003 18:38
Saturday, July 26, 2003, 6:13:18 PM, Tim wrote:
>>> IOWs, where there are two consecutive delimiters, I would like an
>>> empty string inserted.
>> parse/all str to-string delimiters
> Of course! Why didn't I think of that? I've had this code for
> several versions... Thanks Romano.
and once you need multi-char delimiters, you could use
split: func [
{Splits a string delimited by delim into a list of delimited
sub-strings.}
string [any-string!]
delim [any-string!]
/local tokens len pos
] [
tokens: make block! 32
len: length? delim
while [ pos: find string delim ] [
append tokens copy/part string pos
string: skip pos len
]
append tokens copy string
]
>> split "bcadeaafg" "a"
== ["bc" "de" "" "fg"]
>> split "bcadeaafg" "aa"
== ["bcade" "fg"]
--
Best regards,
Andreas