chickadee » srfi-152 » string-index-right

(string-index string pred [start end]) → idx-or-falseprocedure
(string-index-right string pred [start end]) → idx-or-falseprocedure
(string-skip string pred [start end]) → idx-or-falseprocedure
(string-skip-right string pred [start end]) → idx-or-falseprocedure

string-index searches through the given substring from the left, returning the index of the leftmost character satisfying the predicate pred. string-index-right searches from the right, returning the index of the rightmost character satisfying the predicate pred. If no match is found, these procedures return #f.

The start and end arguments specify the beginning and end of the search; the valid indexes relevant to the search include start but exclude end. Beware of "fencepost" errors: when searching right-to-left, the first index considered is (- end 1), whereas when searching left-to-right, the first index considered is start. That is, the start / end indexes describe the same half-open interval [start, end) in these procedures that they do in all other procedures specified by this SRFI.

The skip functions are similar, but use the complement of the criterion: they search for the first char that doesn't satisfy pred. To skip over initial whitespace, for example, say

(substring string
           (or (string-skip string char-whitespace?)
               (string-length string))
           (string-length string))