WJ wrote:
> Erik Naggum wrote:
>
> > (defun delimited-substrings (string &rest delimiters)
> > "Return as multiple values the substrings delimited by each delimiter."
> > (loop
> > with substrings = ()
> > for delimiter in delimiters
> > for start = 0 then (+ end length) ;after last delimiter ends
> > for end = (search delimiter string :start2 start)
> > for length = (length delimiter)
> > do (push (subseq string start end) substrings)
> > until (null end) ;the string was exhausted
> > finally
> > (when end ;the delimiters were exhausted
> > (push (subseq string (+ end length)) substrings))
> > (return (values-list (nreverse substrings)))))
>
> Truly incredible and truly pitiful.
>
> Let's test it:
>
> * (delimited-substrings "foo bar" " ")
>
> "foo"
> " bar"
Gauche Scheme:
(string-split "CLXQISZJCOBOLQZLIKE" #/[XQZJ]+/)
===>
("CL" "IS" "COBOL" "LIKE")
(string-split "CL,IS,COBOL,LIKE" #\,)
===>
("CL" "IS" "COBOL" "LIKE")
(string-split "CLFOOISFOOCOBOLFOOLIKE" "FOO")
===>
("CL" "IS" "COBOL" "LIKE")
(string-split "CL-IS COBOL-LIKE" (cut char<? <> #\A))
===>
("CL" "IS" "COBOL" "LIKE")