Strings.StrComp Method
Assembly: Microsoft.VisualBasic (in microsoft.visualbasic.dll)
'Declaration Public Shared Function StrComp ( _ String1 As String, _ String2 As String, _ <OptionalAttribute> Optional Compare As CompareMethod = CompareMethod.Binary _ ) As Integer 'Usage Dim String1 As String Dim String2 As String Dim Compare As CompareMethod Dim returnValue As Integer returnValue = Strings.StrComp(String1, String2, Compare)
public static int StrComp ( String String1, String String2, /** @attribute OptionalAttribute() */ CompareMethod Compare )
public static function StrComp ( String1 : String, String2 : String, Compare : CompareMethod ) : int
Not applicable.
Parameters
- String1
Required. Any valid String expression.
- String2
Required. Any valid String expression.
- Compare
Optional. Specifies the type of string comparison. If Compare is omitted, the Option Compare setting determines the type of comparison.
Return Value
If String1 sorts ahead of String2, StrComp returns -1. If String1 is equal to String2, StrComp returns 0. If String1 sorts after String2, StrComp returns 1.For more detailed information, see the Visual Basic topic StrComp Function (Visual Basic).
The strings are compared by alphanumeric sort values beginning with the first character. For further information on binary comparisons, textual comparisons, and sort order, see Option Compare Statement.
The Compare argument settings are:
| Constant | Description |
|---|---|
| Binary | Performs a binary comparison, based on a sort order derived from the internal binary representations of the characters. |
| Text | Performs a text comparison, based on a case-insensitive text sort order determined by your system's LocaleID value. |
This example uses the StrComp function to return the results of a string comparison. If the third argument is omitted, the comparison type defined in the Option Compare statement or project defaults is performed.
' Defines variables. Dim TestStr1 As String = "ABCD" Dim TestStr2 As String = "abcd" Dim TestComp As Integer ' The two strings sort equally. Returns 0. TestComp = StrComp(TestStr1, TestStr2, CompareMethod.Text) ' TestStr1 sorts after TestStr2. Returns -1. TestComp = StrComp(TestStr1, TestStr2, CompareMethod.Binary) ' TestStr2 sorts before TestStr1. Returns 1. TestComp = StrComp(TestStr2, TestStr1)
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.