Next: Alphabetic Case in Strings, Previous: Selecting String Components, Up: Strings
Returns
#t
if the two strings (substrings) are the same length and contain the same characters in the same (relative) positions; otherwise returns#f
.string-ci=?
andsubstring-ci=?
don't distinguish uppercase and lowercase letters, butstring=?
andsubstring=?
do.(string=? "PIE" "PIE") => #t (string=? "PIE" "pie") => #f (string-ci=? "PIE" "pie") => #t (substring=? "Alamo" 1 3 "cola" 2 4) => #t ; compares "la"
These procedures compare strings (substrings) according to the order of the characters they contain (also see Comparison of Characters). The arguments are compared using a lexicographic (or dictionary) order. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be less than the longer string.
(string<? "cat" "dog") => #t (string<? "cat" "DOG") => #f (string-ci<? "cat" "DOG") => #t (string>? "catkin" "cat") => #t ; shorter is lesser
If-eq, if-lt, and if-gt are procedures of no arguments (thunks). The two strings are compared; if they are equal, if-eq is applied, if string1 is less than string2, if-lt is applied, else if string1 is greater than string2, if-gt is applied. The value of the procedure is the value of the thunk that is applied.
string-compare
distinguishes uppercase and lowercase letters;
string-compare-ci
does not.(define (cheer) (display "Hooray!")) (define (boo) (display "Boo-hiss!")) (string-compare "a" "b" cheer (lambda() 'ignore) boo) -| Hooray! => unspecified
string-hash
returns an exact non-negative integer that can be used for storing the specified string in a hash table. Equal strings (in the sense ofstring=?
) return equal (=
) hash codes, and non-equal but similar strings are usually mapped to distinct hash codes.
string-hash-mod
is likestring-hash
, except that it limits the result to a particular range based on the exact non-negative integer k. The following are equivalent:(string-hash-mod string k) (modulo (string-hash string) k)