cl:string-split   scheme


Defined in:  https://github.com/lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm

Implementation

;
;; divides a string on a selected char, left or right side
;; returns false if the singlechar is not found
;; the singlechar is excluded from the resulting string
; (cl:string-split "M 3.4, Central California" "," 'right)
(define cl:string-split 
   (lambda (z singlechar left-or-right)
      (if (> (string-length singlechar) 1)
          (print "can't match strings longer than 1 char")
          (let ((pos (cl:string-find z singlechar)))
             (if pos
                 (cond ((equal? left-or-right 'left)
                        (substring z 0 (- pos 1)))
                       ((equal? left-or-right 'right)
                        (substring z pos (string-length z))))
                 #f)))))


Back to Index