Next: , Up: strings compar   [Index]


25.6.1 Lexicographic comparison

Function: %string-compare str1 beg1 past1 str2 beg2 past2 proc< proc= proc>
Function: %string-compare-ci str1 beg1 past1 str2 beg2 past2 proc< proc= proc>
Macro: string-compare S1 S2 proc< proc= proc>
Macro: string-compare-ci S1 S2 proc< proc= proc>

Determine the mismatch index between the two substrings: the largest index i such that for every 0 <= j < i, str1[j] = str2[j]; that is, i is the first position that does not match.

The mismatch index is always an index into str1; in the case of equal strings, it is always past1; the functions observe the protocol in this redundant case for uniformity.

The characters at the mismatch index are compared using char<? or char-ci<?. proc<, proc=, or proc> are applied to the mismatch index (not character), depending upon whether the substring of str1 is less than, equal to, or greater than the substring of str2. The result of the application is returned.

If we just want to have the mismatch index as return value: We can use values as value for proc<, proc= and proc>. Another interesting option is to use (lambda (mismatch-index) #f) or (lambda (mismatch-index) #t).

Examples:

(string-compare "abcd" "abcd" values values values)
⇒ 4

(string-compare "abcd" "abcd12" values values values)
⇒ 4
Function: %string= str1 beg1 past1 str2 beg2 past2
Function: %string-ci= str1 beg1 past1 str2 beg2 past2
Macro: string= S1 S2
Macro: string-ci= S1 S2

Compare two substrings: Return true if they are equal according to char=? or char-ci=?, #f otherwise.

Function: %string<> str1 beg1 past1 str2 beg2 past2
Function: %string-ci<> str1 beg1 past1 str2 beg2 past2
Macro: string<> S1 S1
Macro: string-ci<> S1 S2

Compare two substrings: Return #f if they are equal according to char=? or char-ci=?, true otherwise.

The following predicates are the lexicographic extensions of the corresponding character predicates. A string str1 is “lexicographically” less than str2 if str1 would come first in a dictionary.

Function: %string< str1 beg1 past1 str2 beg2 past2
Function: %string-ci< str1 beg1 past1 str2 beg2 past2
Macro: string< S1 S2
Macro: string-ci< S1 S2

Compare two substrings: Return true if the first is lexicographically less than the second, #f otherwise. If str2 is longer than str1 but the substrings are equal up to the end of str1: Return #t.

(string< "abcd" "abcd") ⇒ #f
(string< "abc"  "abcd") ⇒ #t
(string< "abcd" "abc") ⇒ #f
(string< "ABcd" "abcd") ⇒ #t
(string< "abcd" "a2cd") ⇒ #f

(string-ci< "abcd" "abcd") ⇒ #f
(string-ci< "abc"  "abcd") ⇒ #t
(string-ci< "abcd" "abc") ⇒ #f
(string-ci< "ABcd" "abcd") ⇒ #f
(string-ci< "abcd" "a2cd") ⇒ #f
Function: %string<= str1 beg1 past1 str2 beg2 past2
Function: %string-ci<= str1 beg1 past1 str2 beg2 past2
Macro: string<= S1 S2
Macro: string-ci<= S1 S2

Compare two substrings: Return true if the first is lexicographically less than, or equal to, the second; #f otherwise. If str2 is longer than str1 but the substrings are equal up to the end of str1: Return #t.

(string<= "abcd" "abcd") ⇒ #t
(string<= "abc"  "abcd") ⇒ #t
(string<= "abcd" "abc") ⇒ #f
(string<= "ABcd" "abcd") ⇒ #t
(string<= "abcd" "a2cd") ⇒ #f

(string-ci<= "abcd" "abcd") ⇒ #t
(string-ci<= "abc"  "abcd") ⇒ #t
(string-ci<= "abcd" "abc") ⇒ #f
(string-ci<= "ABcd" "abcd") ⇒ #t
(string-ci<= "abcd" "a2cd") ⇒ #f
Function: %string> str1 beg1 past1 str2 beg2 past2
Function: %string-ci> str1 beg1 past1 str2 beg2 past2
Macro: string> S1 S2
Macro: string-ci> S1 S2

Compare two substrings: Return true if the first is lexicographically greater than the second, #f otherwise. If str1 is longer than str2 but the substrings are equal up to the end of str2: Return #t.

(string> "abcd" "abcd") ⇒ #f
(string> "abcd" "abc") ⇒ #t
(string> "abc"  "abcd") ⇒ #f
(string> "abcd" "ABcd") ⇒ #t
(string> "a2cd" "abcd") ⇒ #f

(string-ci> "abcd" "abcd") ⇒ #f
(string-ci> "abcd" "abc") ⇒ #t
(string-ci> "abc"  "abcd") ⇒ #f
(string-ci> "abcd" "ABcd") ⇒ #f
(string-ci> "a2cd" "abcd") ⇒ #f
Function: %string>= str1 beg1 past1 str2 beg2 past2
Function: %string-ci>= str1 beg1 past1 str2 beg2 past2
Macro: string>= S1 S2
Macro: string-ci>= S1 S2

Compare two substrings: Return true if the first is lexicographically greater than, or equal to, the second; #f otherwise. If str1 is longer than str2 but the substrings are equal up to the end of str2: Return #t.

(string>= "abcd" "abcd") ⇒ #t
(string>= "abcd" "abc") ⇒ #t
(string>= "abc" "abcd") ⇒ #f
(string>= "abcd" "ABcd") ⇒ #t
(string>= "a2cd" "abcd") ⇒ #f

(string-ci>= "abcd" "abcd") ⇒ #t
(string-ci>= "abcd" "abc") ⇒ #t
(string-ci>= "abc"  "abcd") ⇒ #f
(string-ci>= "abcd" "ABcd") ⇒ #t
(string-ci>= "a2cd" "abcd") ⇒ #f

Next: , Up: strings compar   [Index]