1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
<RefEntry id="string-index">
<!-- This file is generated automatically from the DSSSL source. -->
<!-- Do not edit this file! -->
<?html-filename string-index.html>
<RefMeta>
<RefEntryTitle>string-index</RefEntryTitle>
<RefMiscInfo Role="file">dblib.dsl</RefMiscInfo>
</RefMeta>
<RefNameDiv>
<RefName>string-index</RefName>
<RefPurpose>Finds first occurance of 'target' in 'source'</RefPurpose>
</RefNameDiv>
<RefSynopsisDiv><Title>Synopsis</Title>
<Synopsis>
(string-index source target)
</Synopsis>
</RefSynopsisDiv>
<RefSect1><Title>Description</Title>
<para>
Returns the position of the first occurance of <literal>target</literal> in <literal>source</literal>,
or -1 if it does not occur.</para>
</RefSect1>
<RefSect1><Title>Author</Title>
<para>
Norman Walsh, <ndw@nwalsh.com>
</para>
</RefSect1>
<RefSect1><Title>Source Code</Title>
<ProgramListing>
(define (string-index source target)
;; Finds first occurance of 'target' in 'source'
(let loop ((str source) (pos 0))
(if (< (string-length str) (string-length target))
-1
(if (string=? (substring str 0 (string-length target)) target)
pos
(loop (substring str 1 (string-length str))
(+ pos 1))))))
</ProgramListing>
</RefSect1>
</RefEntry>
|