Node:String Searching, 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.

string-index str chr [frm [to]] Scheme Procedure
scm_string_index (str, chr, frm, to) C Function
Return the index of the first occurrence of chr in str. The optional integer arguments frm and to limit the search to a portion of the string. This procedure essentially implements the index or strchr functions from the C library.
(string-index "weiner" #\e)
=> 1

(string-index "weiner" #\e 2)
=> 4

(string-index "weiner" #\e 2 4)
=> #f

string-rindex str chr [frm [to]] Scheme Procedure
scm_string_rindex (str, chr, frm, to) C Function
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