Next: , Previous: , Up: Sorting and Searching   [Contents][Index]


7.2.9 String Search

(require 'string-search)

Procedure: string-index string char
Procedure: string-index-ci string char

Returns the index of the first occurence of char within string, or #f if the string does not contain a character char.

Procedure: string-reverse-index string char
Procedure: string-reverse-index-ci string char

Returns the index of the last occurence of char within string, or #f if the string does not contain a character char.

Procedure: substring? pattern string
Procedure: substring-ci? pattern string

Searches string to see if some substring of string is equal to pattern. substring? returns the index of the first character of the first substring of string that is equal to pattern; or #f if string does not contain pattern.

(substring? "rat" "pirate") ⇒  2
(substring? "rat" "outrage") ⇒  #f
(substring? "" any-string) ⇒  0
Procedure: find-string-from-port? str in-port max-no-chars

Looks for a string str within the first max-no-chars chars of the input port in-port.

Procedure: find-string-from-port? str in-port

When called with two arguments, the search span is limited by the end of the input stream.

Procedure: find-string-from-port? str in-port char

Searches up to the first occurrence of character char in str.

Procedure: find-string-from-port? str in-port proc

Searches up to the first occurrence of the procedure proc returning non-false when called with a character (from in-port) argument.

When the str is found, find-string-from-port? returns the number of characters it has read from the port, and the port is set to read the first char after that (that is, after the str) The function returns #f when the str isn’t found.

find-string-from-port? reads the port strictly sequentially, and does not perform any buffering. So find-string-from-port? can be used even if the in-port is open to a pipe or other communication channel.

Function: string-subst txt old1 new1 …

Returns a copy of string txt with all occurrences of string old1 in txt replaced with new1; then old2 replaced with new2 …. Matches are found from the left. Matches do not overlap.

Function: count-newlines str

Returns the number of ‘#\newline’ characters in string str.


Next: , Previous: , Up: Sorting and Searching   [Contents][Index]