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:
CompareMethod
constantEither
CompareMethod.Binary
orCompareMethod.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
compare
argument is one ofCompareMethod.Binary
orCompareMethod.Text
. If no comparison is specified, VB uses the value ofOption
Compare
.The following table describes the possible return values from the
StrComp
function:
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
StrComp
function can provide a significant performance improvement (in the neighborhood of 30% to 70%) over the comparison operators.
See Also
Get VB .NET Language in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.