Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Splitting string based on substring separator

From: andreas:bolka:gmx at: 22-Dec-2002 2:23

Sunday, December 22, 2002, 1:19:59 AM, SunandaDH wrote:
> Frantisek : >> and I want to split it to substrings based on the separator string >> (in this case, "sep"). > I'm sure you may get more elegant answers, but when I was faced with > the same problem, I solved it by replacing the "sep" string with a > single character that did not (should not!) appear in the string, I > used a hex ff -- so:
funny enough, that i was hacking around at the same thing the very moment (although only remotely related to what i really wanted to do :). below you'll find my current version of 'split - tell me how it works (it should even work with binary! as it preserves the original series type :) -- snip -- split: func [ string delim /local tokens token pos ] [ string: copy string ; resets series pointer - index? points to 1 tokens: copy [] while [ (not tail? string) and (found? pos: find string delim) ] [ token: copy/part string -1 + index? pos string: copy skip string (length? token) + (length? delim) append tokens token ] append tokens copy string ] -- snap -- -- Best regards, Andreas mailto:[andreas--bolka--gmx--net]