string-replace

Name

string-replace -- Replace all occurances of a target substring in a string

Synopsis

(string-replace string target repl)

Description

Replaces all occurances of target in string with repl.

Author

Norman Walsh, <ndw@nwalsh.com>

Source Code

(define (string-replace string target repl)
  ;; Replace all occurances of a target substring in a string
  (let loop ((str string) (pos 0))
    (if (>= pos (string-length str))
	str
	(loop (repl-substring str target repl pos) 
	      (if (repl-substring? str target pos)
		  (+ (string-length repl) pos)
		  (+ 1 pos))))))