trim-string

Name

trim-string -- Trims the tail off of a string

Synopsis

(trim-string str string-list)

Description

If str ends with any of the strings in string-list, trim that string off and return the base string. E.g., (trim-string "filename.sgm" (".sgm" ".xml" ".sgml")) returns "filename".

Author

Norman Walsh, <ndw@nwalsh.com>

Source Code

(define (trim-string str string-list)
  ;; Trims the tail off of a string
  (let ((strlen (string-length str)))
    (let loop ((sl string-list))
      (if (null? sl)
	  str
	  (if (equal? 
	       (substring str (- strlen (string-length (car sl))) strlen)
	       (car sl))
	      (substring str 0 (- strlen (string-length (car sl))))
	      (loop (cdr sl)))))))