(defun split-string (string &optional (separators " ,-"))
"Splits STRING into a list of substrings (which is returned)
separated by the characters in the sequence SEPARATORS. Empty
substrings aren't collected."
(flet ((make-collector ()
(make-array 0
:adjustable t
:fill-pointer t
:element-type #+:lispworks 'lw:simple-char
#-:lispworks 'character)))
(loop with collector = (make-collector)
for char across string
for counter downfrom (1- (length string))
when (find char separators :test #'char=)
when (plusp (length collector))
collect collector
and do (setq collector (make-collector))
(vector-push-extend char collector)
else do (vector-push-extend char collector) end
else
do (vector-push-extend char collector)
and when (zerop counter) collect collector)))
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 299 |
Nodes: | 16 (2 / 14) |
Uptime: | 28:48:57 |
Calls: | 6,681 |
Calls today: | 4 |
Files: | 12,222 |
Messages: | 5,342,516 |
Posted today: | 2 |