O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

StrComp Function

Class

Microsoft.VisualBasic.Strings

Syntax

StrComp(string1, string2[, compare])
string1 (required; String)

Any string expression

string2 (required; String)

Any string expression

compare (optional; CompareMethod constant)

Either CompareMethod.Binary or CompareMethod.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 of CompareMethod.Binary or CompareMethod.Text. If no comparison is specified, VB uses the value of Option 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

string1 or string2 is Null

Null

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required