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 53 54 55 56
|
<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, <ndw@nwalsh.com>
</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>
|