Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 23 |
Nodes: | 6 (0 / 6) |
Uptime: | 52:44:09 |
Calls: | 583 |
Files: | 1,139 |
D/L today: |
179 files (27,921K bytes) |
Messages: | 111,617 |
How to read a comma separated list from a file.
For example, " 2, 3, 5, 6,".
I assume you want to read only one line, every item is an integer and
empty entries should be ignored (after your last comma). Here is a
recursive solution:
(defun split (string delimiter)
(when (= 0 (length delimiter)) (error "delimiter length = 0"))
(let ((start (search delimiter string)))
(if (not start)
(if (= 0 (length string))
nil
(list string))
(let ((value (string-trim '(#\Space) (subseq string 0 start)))
(rest (subseq string (+ start (length delimiter)))))
(if (= 0 (length value))
(split rest delimiter)
(cons value (split rest delimiter)))))))