<RefEntry id="strip"> <!-- This file is generated automatically from the DSSSL source. --> <!-- Do not edit this file! --> <?html-filename strip.html> <RefMeta> <RefEntryTitle>strip</RefEntryTitle> <RefMiscInfo Role="file">dblib.dsl</RefMiscInfo> </RefMeta> <RefNameDiv> <RefName>strip</RefName> <RefPurpose>Strip leading and trailing characters off of a string</RefPurpose> </RefNameDiv> <RefSynopsisDiv><Title>Synopsis</Title> <Synopsis> (strip str #!optional (stripchars '(#\space #\&#RE #\U-0009))) </Synopsis> </RefSynopsisDiv> <RefSect1><Title>Description</Title> <para> Strips leading and trailing characters in the <literal>stripchars</literal> list off of a string and returns the stripped string. </para> <variablelist> <varlistentry><term><literal>str</literal></term> <listitem> <para> The string to strip </para> </listitem> </varlistentry> <varlistentry><term><literal>stripchars</literal></term> <listitem> <para> A list of characters that should be stripped. </para> </listitem> </varlistentry> </variablelist> </RefSect1> <RefSect1><Title>Author</Title> <para> Norman Walsh, <ndw@nwalsh.com> </para> </RefSect1> <RefSect1><Title>Source Code</Title> <ProgramListing> (define (strip str #!optional (stripchars '(#\space #\&#RE #\U-0009))) ;; Strip leading and trailing characters off of a string (let* ((startpos (let loop ((count 0)) (if (>= count (string-length str)) (string-length str) (if (member (string-ref str count) stripchars) (loop (+ count 1)) count)))) (tailstr (substring str startpos (string-length str))) (endpos (let loop ((count (- (string-length tailstr) 1))) (if (< count 1) 0 (if (member (string-ref tailstr count) stripchars) (loop (- count 1)) count))))) (if (or (< endpos 0) (string=? tailstr "")) "" (substring tailstr 0 (+ endpos 1))))) </ProgramListing> </RefSect1> </RefEntry>