Next: , Previous: Searching Strings, Up: Strings


6.7 Matching Strings

— procedure: string-match-forward string1 string2
— procedure: substring-match-forward string1 start end string2 start end
— procedure: string-match-forward-ci string1 string2
— procedure: substring-match-forward-ci string1 start end string2 start end

Compares the two strings (substrings), starting from the beginning, and returns the number of characters that are the same. If the two strings (substrings) start differently, returns 0. The -ci procedures don't distinguish uppercase and lowercase letters.

          (string-match-forward "mirror" "micro") =>  2  ; matches "mi"
          (string-match-forward "a" "b")          =>  0  ; no match
     
— procedure: string-match-backward string1 string2
— procedure: substring-match-backward string1 start end string2 start end
— procedure: string-match-backward-ci string1 string2
— procedure: substring-match-backward-ci string1 start end string2 start end

Compares the two strings (substrings), starting from the end and matching toward the front, returning the number of characters that are the same. If the two strings (substrings) end differently, returns 0. The -ci procedures don't distinguish uppercase and lowercase letters.

          (string-match-backward-ci "BULBOUS" "fractious")
                                                  =>  3  ; matches "ous"
     
— procedure: string-prefix? string1 string2
— procedure: substring-prefix? string1 start1 end1 string2 start2 end2
— procedure: string-prefix-ci? string1 string2
— procedure: substring-prefix-ci? string1 start1 end1 string2 start2 end2

These procedures return #t if the first string (substring) forms the prefix of the second; otherwise returns #f. The -ci procedures don't distinguish uppercase and lowercase letters.

          (string-prefix? "abc" "abcdef")         =>  #t
          (string-prefix? "" any-string)          =>  #t
     
— procedure: string-suffix? string1 string2
— procedure: substring-suffix? string1 start1 end1 string2 start2 end2
— procedure: string-suffix-ci? string1 string2
— procedure: substring-suffix-ci? string1 start1 end1 string2 start2 end2

These procedures return #t if the first string (substring) forms the suffix of the second; otherwise returns #f. The -ci procedures don't distinguish uppercase and lowercase letters.

          (string-suffix? "ous" "bulbous")        =>  #t
          (string-suffix? "" any-string)          =>  #t