Compare two strings for equality.
Syntax
StrComp(String1, String2 [,compare])
Key
String1 A string expression.
String2 A string expression.
compare The type of comparison.
0 (default) = Binary compare
1 = Text compare
2 = Access compare
A Binary comparison compares the numeric Unicode value of each character in the string. A Text comparison compares each Unicode character based on its lexical meaning in the current culture. Different languages might have a different alphabetical order.
Result returned:
| String1 < String2 | -1 |
| String1 = String2 | 0 |
| String1 > String2 | 1 |
| String1 or String2 = NULL | NULL |
The StrComp() function can be used in VBA or in an SQL query.
Examples
Dim intDemo as Integer
intDemo = StrComp("universe", "apple")
MsgBox
intDemo
'Returns: 1
intDemo = StrComp("universe", "universe")
'Returns: 0
“To compare is not to prove” ~ French Proverb
Related:
IIf - If-Then-Else function