Created
September 4, 2020 17:20
-
-
Save jfacoustic/72ca11400fb108225393ec4a23a79109 to your computer and use it in GitHub Desktop.
Splits string by delimiter; default delimiter is \#space. (split-string "1 2 3 4") evaluates to ("1" "2" "3" "4").
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun split-string (str &key (delimiter #\space)) | |
(defun split-string-rec (str str-list delimiter-pos) | |
(if delimiter-pos | |
(let ((current (subseq str 0 delimiter-pos)) | |
(remaining (subseq str (+ delimiter-pos 1) (length str)))) | |
(split-string-rec remaining | |
(push current str-list) | |
(position delimiter remaining))) | |
(reverse (push str str-list)))) | |
(split-string-rec str nil (position delimiter str))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment