DSSSL Library Reference: Part of the Modular DocBook Stylesheet distribution
Prev |  | Next

# 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))))))

Prev | Home | Next
repl-substring-list | Up | string-replace-list