StrComp Function

Makes a binary (case-sensitive) or text (lexicographic) comparison of the two strings passed and returns the result.

Syntax
result = StrComp( string1, string2, mode )
result = stringVariable.StrComp( string2, mode )

Parameters
string1 | String | The first string for comparison.
string2 | String | The second string for comparison.
mode | Integer | The comparison mode: 0=binary (case-sensitive) 1=text (lexicographic)

Return Value
Result | Integer | If string1 < string2 the function returns -1 If string1 = string2 the function returns 0 If string1 > string2 the function returns 1

# Notes

The text comparison is lexicographic, not case-insensitive. The means that case will be taken into account if the strings are the same (other than case).

When using Mode 0 (binary), StrComp always compares the bytes of the strings as they are, doing no encoding conversions. It's possible that two strings might look the same on screen but be reported as different in StrComp Mode 0 if they are in different encodings (and, therefore, contain different bytes).

# Examples

The following example returns -1 because the two strings are the same in every way except in case.

StrComp("Spam", "spam", 1)

The following example returns -1 because in a text comparison of the two strings, string2 is greater than string1. The ASCII value of "s" is greater than the ASCII value of "S".

StrComp("Spam", "spam", 0)

# See Also

InStr function; >, >=, <, <=, =, <> operators.