Next: , Previous: , Up: strings compar   [Index]


25.6.3 String and numeric parts lexicographic comparison

String/numbers comparison splits the strings to compare into their numeric and non–numeric parts and compares the parts one by one; for example, the string ‘foo4bar3zab10’ is split into the following list:

("foo" 4 "bar" 3 "zab" 10)

in which non–numeric parts are retained as Scheme strings and numeric parts become exact integers; numeric parts only become exact integer, never flonums. String parts are compared with the ordinary lexicographic operators string<? and string=? (or string-ci<? and string-ci=?), while numeric parts are compared with the ordinary < and = operators; a string part and a numeric part are compared by converting the number into a string, then using string<? and string=?.

Miscellaneous examples:

(string/numbers<? "123" "45")
⇒ #f

(string/numbers<? "ciao3" "ciao10")
⇒ #t

(string/numbers<? "foo4bar3zab10" "foo4bar3zab2")
⇒ #f

(string/numbers<? "foo4bar10" "foo4bar3zab")
⇒ #f
Function: string/numbers-compare str1 str2
Function: %string/numbers-compare str1 str2

Compare the string and numeric parts of the arguments and return a ternary result: ‘-1’ if str1 is less than str2, ‘0’ if str1 is equal to str2, ‘+1’ if str1 is greater than str2. The comparison is case sensitive.

Function: string/numbers=? str1 str2
Function: string/numbers<>? str1 str2
Function: string/numbers<? str1 str2
Function: string/numbers<=? str1 str2
Function: string/numbers>? str1 str2
Function: string/numbers>=? str1 str2
Function: %string/numbers=? str1 str2
Function: %string/numbers<>? str1 str2
Function: %string/numbers<? str1 str2
Function: %string/numbers<=? str1 str2
Function: %string/numbers>? str1 str2
Function: %string/numbers>=? str1 str2

Return #t or #f, whether the string arguments comply with the predicate.

Function: string/numbers-compare-ci str1 str2
Function: %string/numbers-compare-ci str1 str2

Compare the string and numeric parts of the arguments and return a ternary result: ‘-1’ if str1 is less than str2, ‘0’ if str1 is equal to str2, ‘+1’ if str1 is greater than str2. The comparison is case insensitive.

Function: string/numbers-ci=? str1 str2
Function: string/numbers-ci<>? str1 str2
Function: string/numbers-ci<? str1 str2
Function: string/numbers-ci>? str1 str2
Function: string/numbers-ci<=? str1 str2
Function: string/numbers-ci>=? str1 str2
Function: %string/numbers-ci=? str1 str2
Function: %string/numbers-ci<>? str1 str2
Function: %string/numbers-ci<? str1 str2
Function: %string/numbers-ci>? str1 str2
Function: %string/numbers-ci<=? str1 str2
Function: %string/numbers-ci>=? str1 str2

Return #t or #f, whether the string arguments comply with the predicate. The comparison is case insensitive.


Next: , Previous: , Up: strings compar   [Index]