[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: Tokenizer (Re: Most efficient way to read words from string.

William James

1/23/2016 9:35:00 PM

Marco Antoniotti wrote:

> (defun string-split (str &optional (separator #\Space))
> "Splits the string STR at each SEPARATOR character occurrence.
> The resulting substrings are collected into a list which is returned.
> A SEPARATOR at the beginning or at the end of the string STR results
> in an empty string in the first or last position of the list
> returned."
> (declare (type string str)
> (type character separator))
> (loop for start = 0 then (1+ end)
> for end = (position separator str :start 0)
> then (position separator str :start start)
> for substr = (subseq str start end)
> then (subseq str start end)
> collect substr into result
> when (null end) do (return result)
> ))

Testing:

CL-USER(2): (string-split "foo bar")
("foo" "" "" "" "" "" "bar")

MatzLisp (Ruby):

"foo bar \t why".split
==>["foo", "bar", "why"]

--
Amazon bans book. After nearly a month on the site, all traces of the book and
its 80 reviews have been removed.
http://jamesfetzer.blogspot.com/2015/11/debunking-sandy-hook-debunk...
https://www.youtube.com/watch?v=E...