int = StrCompare(sOne, sTwo, bCaseSensitive)
This macro function compares sOne and sTwo. It returns +1 if sOne comes before sTwo in the comparison order, 0 if they compare equal, and -1 if sOne comes after sTwo.
➢The sign convention is +1 for "before" and -1 for "after". Use this convention when deciding which string to place first in a sorted list.
This function is used to sort strings.
StrCompare('A', 'Z', false); // returns +1
StrCompare('AAA', 'aaaa', false); // returns +1
StrCompare('AAAB', 'aaaa', false); // returns -1
StrCompare('A', 'a', false); // returns 0
StrCompare('Aaaa', 'aaaa', false); // returns 0
The Boolean parameter, bCaseSensitive, determines if the comparison is to take uppercase and lowercase letters into account.
StrCompare('A', 'Z', true); // returns +1
StrCompare('AAA', 'aaaa', true); // returns +1
StrCompare('AAAB', 'aaaa', true); // returns +1
StrCompare('A', 'a', true); // returns +1
StrCompare('Aaaa', 'aaaa', true); // returns +1
StrCompare('Z', 'A', true); // returns -1
The comparison uses character values (ordinal order), with case ignored when bCaseSensitive is false. Windows regional settings do not select a language-specific alphabetical order for this function; bear this in mind when sorting names containing accented letters.
See also: StrContains.
Topic 137200, last updated on 18-Apr-2020