Next: , Previous: String Comparison, Up: Strings


21.4.8 String Searching

When searching for the index of a character in a string, these procedures can be used.

— Scheme Procedure: string-index s char_pred [start [end]]
— C Function: scm_string_index (s, char_pred, start, end) |2 |2 |0

Search through the string s from left to right, returning the index of the first occurence of a character which

— Scheme Procedure: string-rindex str chr [frm [to]]
— C Function: scm_string_rindex (str, chr, frm, to) |2 |2 |0

Like string-index, but search from the right of the string rather than from the left. This procedure essentially implements the rindex or strrchr functions from the C library.

          (string-rindex "weiner" #e)
          ⇒ 4
          
          (string-rindex "weiner" #e 2 4)
          ⇒ #f
          
          (string-rindex "weiner" #e 2 5)
          ⇒ 4