Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-release > by-pkgid > 6b3585ea67ce3e79c9049b5b33294cdd > files > 691

docbook-style-dsssl-doc-1.79-16.mga7.noarch.rpm

<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, &lt;ndw@nwalsh.com&gt;
</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>