Skip to content

Instantly share code, notes, and snippets.

@siguremon
Created August 27, 2011 04:38
Show Gist options
  • Save siguremon/1174988 to your computer and use it in GitHub Desktop.
Save siguremon/1174988 to your computer and use it in GitHub Desktop.
split string function in common lisp
(defun split-str (string &optional (separator " "))
(split-str-1 string separator))
(defun split-str-1 (string &optional (separator " ") (r nil))
(let ((n (position separator string
:from-end t
:test #'(lambda (x y)
(find y x :test #'string=)))))
(if n
(split-str-1 (subseq string 0 n) separator (cons (subseq string (1+ n)) r))
(cons string r))))
@Aadv1k
Copy link

Aadv1k commented May 9, 2023

Thanks!

@ispringle
Copy link

This only seems to work with single char separators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment