StrCompare

Compares two strings alphabetically.

Result := StrCompare(String1, String2 , CaseSense := false)

Parameters

String1, String2

Type: String

The strings to be compared.

CaseSense

Type: Integer or String

One of the following values (defaults to 0 if omitted):

"On" or 1 (True): The comparison is case sensitive.

"Off" or 0 (False): The letters A-Z are considered identical to their lowercase counterparts.

"Locale": The comparison is case insensitive according to the rules of the current user's locale. For example, most English and Western European locales treat not only the letters A-Z as identical to their lowercase counterparts, but also non-ASCII letters like Ä and Ü as identical to theirs. Locale is 1 to 8 times slower than Off depending on the nature of the strings being compared.

"Logical": Like Locale, but digits in the strings are considered as numerical content rather than text. For example, "A2" is considered less than "A10". However, if two numbers differ only by the presence of a leading zero, the string with leading zero may be considered less than the other string. The exact behavior may differ between OS versions.

Return Value

Type: Integer

To indicate the relationship between String1 and String2, this function returns one of the following:

To check for a specific relationship between the two strings, compare the result to 0. For example:

a_less_than_b := StrCompare(a, b) < 0
a_greater_than_or_equal_to_b := StrCompare(a, b) >= 0

Remarks

This function is commonly used for sort callbacks.

Related

Sort

Examples

#1

MsgBox StrCompare("Abc", "abc") ; Returns 0
MsgBox StrCompare("Abc", "abc", true) ; Returns -1