Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 23 |
Nodes: | 6 (0 / 6) |
Uptime: | 52:44:06 |
Calls: | 583 |
Files: | 1,139 |
D/L today: |
179 files (27,921K bytes) |
Messages: | 111,617 |
(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)
))
(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)
))
NIL
("stringtolist")
("stringtolist")
("stringtolist")
("stringtolist")
("string" "to" "list")
("string" "to" "list")
("string" "to" "list")
Gauche Scheme
"!" is similar to "do".
(define (tokenize str separators)
(let ((seps (string->list separators)))
(! (ch :in (reverse (cons (car seps) (string->list str)))
:= sep (member ch seps)
r cons (list->string tmp) :if (and (pair? tmp) sep)
tmp '() (if sep '() (cons ch tmp)))
#f r)))
(tokenize " foo; bar, baz, and ... zap" " ,;.")
===>
("foo" "bar" "baz" "and" "zap")
NIL
(" ")
("string" "to" "list")
("string" "to" "list")
("string" "to" "list")
("string" "to" "list")
("string" "to" "list")
("string" "to" "list")
("string" "to" "list")--