Name
StrComp Function
Class
Microsoft.VisualBasic.Strings
Syntax
StrComp(string1, string2[, compare])-
string1 Use: Required
Data Type: String
Any string expression
-
string2 Use: Required
Data Type: String
Any string expression
-
compare Use: Optional
Data Type:
CompareMethodconstantEither
CompareMethod.BinaryorCompareMethod.Text
Return Value
Integer
Description
Determines whether two strings are equal and, if not, which of two strings has the greater value
Rules at a Glance
The
compareargument is one ofCompareMethod.BinaryorCompareMethod.Text. If no comparison is specified, VB uses the value ofOptionCompare.The following table describes the possible return values from the
StrCompfunction:
|
Scenario |
Return value |
|---|---|
string1 < string2
|
-1 |
string1 = string2
|
0 |
string1 > string2
|
1 |
|
|
|
Programming Tips and Gotchas
Using the comparison operators
<,<=,>, and>=to compare strings performs a character-by-character binary comparison.The
StrCompfunction can provide a significant performance improvement (in the neighborhood of 30% to 70%) over the comparison operators.
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access