Go to the previous, next section.

Searching Strings

procedure+: substring? pattern string

Searches string to see if it contains the substring pattern. Returns the index 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
(if (substring? "moon" text)
    (process-lunar text)
    'no-moon)

procedure+: string-find-next-char string char

procedure+: substring-find-next-char string start end char

procedure+: string-find-next-char-ci string char

procedure+: substring-find-next-char-ci string start end char

Returns the index of the first occurrence of char in the string (substring); returns #f if char does not appear in the string. For the substring procedures, the index returned is relative to the entire string, not just the substring. The -ci procedures don't distinguish uppercase and lowercase letters.

(string-find-next-char "Adam" #\A)              =>  0 
(substring-find-next-char "Adam" 1 4 #\A)       =>  #f
(substring-find-next-char-ci "Adam" 1 4 #\A)    =>  2 

procedure+: string-find-next-char-in-set string char-set

procedure+: substring-find-next-char-in-set string start end char-set

Returns the index of the first character in the string (or substring) that is also in char-set, or returns #f if none of the characters in char-set occur in string. For the substring procedure, only the substring is searched, but the index returned is relative to the entire string, not just the substring.

(string-find-next-char-in-set my-string char-set:alphabetic)
                =>  start position of the first word in my-string
; Can be used as a predicate:
(if (string-find-next-char-in-set my-string (char-set #\( #\) ))
    'contains-parentheses
    'no-parentheses)

procedure+: string-find-previous-char string char

procedure+: substring-find-previous-char string start end char

procedure+: string-find-previous-char-ci string char

procedure+: substring-find-previous-char-ci string start end char

Returns the index of the last occurrence of char in the string (substring); returns #f if char doesn't appear in the string. For the substring procedures, the index returned is relative to the entire string, not just the substring. The -ci procedures don't distinguish uppercase and lowercase letters.

procedure+: string-find-previous-char-in-set string char-set

procedure+: substring-find-previous-char-in-set string start end char-set

Returns the index of the last character in the string (substring) that is also in char-set. For the substring procedure, the index returned is relative to the entire string, not just the substring.

Go to the previous, next section.