Here are some functions I've written to convert strings into....
lists of various sorts. Examples follow at the end.
(defun list-from-string (string
&key
(start 0)
(char-bag '(#\Space))
(test #'(lambda (ch)
(not (member ch char-bag
:test 'char=))))
(post-process 'identity))
(let ((pos (position-if test string :start start)))
(if pos
(list-from-string* string :start pos :char-bag char-bag
:test test :post-process post-process)
nil)))
(defun list-from-string* (string
&key
(start 0)
(char-bag '(#\Space))
(test #'(lambda (ch)
(not (member ch char-bag :test 'char=))))
(post-process 'identity))
(let* ((pos (position-if-not test string :start start))
(new-pos (if pos (position-if test string :start pos) nil)))
(cond
((and pos new-pos)
(cons (funcall post-process (subseq string start pos))
(list-from-string* string :start new-pos :char-bag char-bag
:test test :post-process post-process)))
(pos (list (funcall post-process (subseq string start pos))))
(t (list (funcall post-process (subseq string start)))))))
(list-from-string "chris! dan! ski! elaine! nick!"
:char-bag '(#\Space #\!)) -->
("chris" "dan" "ski" "elaine" "nick")
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 462 |
Nodes: | 16 (2 / 14) |
Uptime: | 125:02:29 |
Calls: | 9,377 |
Files: | 13,555 |
Messages: | 6,092,993 |