Sophie

Sophie

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

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

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

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

<RefNameDiv>
  <RefName>trim-string</RefName>
  <RefPurpose>Trims the tail off of a string</RefPurpose>
</RefNameDiv>

<RefSynopsisDiv><Title>Synopsis</Title>
<Synopsis>
(trim-string str string-list)
</Synopsis>
</RefSynopsisDiv>

<RefSect1><Title>Description</Title>

<para>
If <literal>str</literal> ends with any of the strings in <literal>string-list</literal>, trim that
string off and return the base string.
E.g., <literal>(trim-string "filename.sgm" </literal>(".sgm" ".xml" ".sgml"))
returns "filename".</para>


</RefSect1>

<RefSect1><Title>Author</Title>

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

<ProgramListing>
(define (trim-string str string-list)
  ;; Trims the tail off of a string
  (let ((strlen (string-length str)))
    (let loop ((sl string-list))
      (if (null? sl)
	  str
	  (if (equal? 
	       (substring str (- strlen (string-length (car sl))) strlen)
	       (car sl))
	      (substring str 0 (- strlen (string-length (car sl))))
	      (loop (cdr sl)))))))
</ProgramListing>
</RefSect1>

</RefEntry>