Strips leading and trailing characters in the stripchars list off of a string and returns the stripped string.
The string to strip
A list of characters that should be stripped.
(define (strip str #!optional (stripchars '(#\space #\ #\U-0009))) ;; Strip leading and trailing characters off of a string (let* ((startpos (let loop ((count 0)) (if (>= count (string-length str)) (string-length str) (if (member (string-ref str count) stripchars) (loop (+ count 1)) count)))) (tailstr (substring str startpos (string-length str))) (endpos (let loop ((count (- (string-length tailstr) 1))) (if (< count 1) 0 (if (member (string-ref tailstr count) stripchars) (loop (- count 1)) count))))) (if (or (< endpos 0) (string=? tailstr "")) "" (substring tailstr 0 (+ endpos 1)))))