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: rotenca:telvia:it at: 23-Dec-2002 20:13

Hi all,
> behave different - the 'parse version inserts 'none tokens when > nothing is between two delimiters > > split ":1::2:" ":" > ; == [ none "1" none "2" none ] > > while the 'find based version inserts empty strings instead (the > latter behaviour matching my original intentions). > > So here it is, the slightly improved (and still _very_ fast) 'parse > based split, that handles empty non-tokens nicely: > > split: func [string delim /local tokens token] [ > > tokens: make block! 32 > > parse/all string [ > > any [copy token to delim (append tokens token) delim] > > copy token to end (append tokens token) > > ] > > tokens > > ]
There is a little problem: to copy the empty string: split: func [ string delim /local tokens token ] [ tokens: make block! 32 parse/all string [ any [copy token to delim delim (insert tail tokens any [token copy ])] copy token to end (insert tail tokens any [token copy ""]) ] tokens ] (insert tail is faster than append) --- Ciao Romano