- (string-index s char/char-set/pred [start end]) -> integer or #fprocedure
- (string-index-right s char/char-set/pred [start end]) -> integer or #fprocedure
- (string-skip s char/char-set/pred [start end]) -> integer or #fprocedure
- (string-skip-right s char/char-set/pred [start end]) -> integer or #fprocedure
string-index (string-index-right) searches through the string from the left (right), returning the index of the first occurrence of a character which
- equals CHAR/CHAR-SET/PRED (if it is a character);
- is in CHAR/CHAR-SET/PRED (if it is a character set);
- satisfies the predicate CHAR/CHAR-SET/PRED (if it is a procedure).
If no match is found, the functions return false.
The START and END parameters specify the beginning and end indices of the search; the search includes the start index, but not the end index. Be careful of "fencepost" considerations: 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 indices describe a same half-open interval [START,END) in these procedures that they do in all the other SRFI 13 procedures.
The skip functions are similar, but use the complement of the criteria: they search for the first char that doesn't satisfy the test. E.g., to skip over initial whitespace, say
(cond ((string-skip s char-set:whitespace) =>
(lambda (i) ...)) ; s[i] is not whitespace. ...)