Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 27 |
Nodes: | 6 (0 / 6) |
Uptime: | 41:24:32 |
Calls: | 631 |
Calls today: | 2 |
Files: | 1,187 |
D/L today: |
24 files (29,813K bytes) |
Messages: | 174,725 |
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)))))))