<RefEntry id="string-replace">
<!-- This file is generated automatically from the DSSSL source. -->
<!-- Do not edit this file! -->
<?html-filename string-replace.html>

<RefMeta>
  <RefEntryTitle>string-replace</RefEntryTitle>
  <RefMiscInfo Role="file">dblib.dsl</RefMiscInfo>
</RefMeta>

<RefNameDiv>
  <RefName>string-replace</RefName>
  <RefPurpose>Replace all occurances of a target substring in a string</RefPurpose>
</RefNameDiv>

<RefSynopsisDiv><Title>Synopsis</Title>
<Synopsis>
(string-replace string target repl)
</Synopsis>
</RefSynopsisDiv>

<RefSect1><Title>Description</Title>

<para>
Replaces all occurances of <literal>target</literal> in <literal>string</literal> with <literal>repl</literal>.</para>


</RefSect1>

<RefSect1><Title>Author</Title>

<para>
Norman Walsh, &lt;ndw@nwalsh.com&gt;
</para>
</RefSect1>
<RefSect1><Title>Source Code</Title>

<ProgramListing>
(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))))))
</ProgramListing>
</RefSect1>

</RefEntry>
