Compares two strings with the default CultureInfo information.
[Visual Basic] Overloads Public Shared Function Compare( _ ByVal strA As String, _ ByVal indexA As Integer, _ ByVal strB As String, _ ByVal indexB As Integer, _ ByVal length As Integer _ ) As Integer [C#] public static int Compare( string strA, int indexA, string strB, int indexB, int length ); [C++] public: static int Compare( String* strA, int indexA, String* strB, int indexB, int length ); [JScript] public static function Compare( strA : String, indexA : int, strB : String, indexB : int, length : int ) : int;
Value Type | Condition |
---|---|
A negative integer | If region A is less than region B. |
0 | If the two regions of length are equal. |
A positive integer | If region A is greater than region B. |
Exception Type | Condition |
---|---|
ArgumentNullException | If either string is null. |
ArgumentOutOfRangeException | If either index is out of range. |
ArgumentOutOfRangeException | If length is negative. |
The Compare method does a locale sensitive comparison of two strings and returns a integer representation of their relationship with the specific culture information from CultureInfo.
One string may be "less than" or "greater than" another string depending upon the rules of the national language under which the comparison is made. To compare strings without regard to national languages, see CompareOrdinal. and CurrentCulture.
The region of the first string of length, beginning at the position of the the first index, is compared with the region of the second string of length, beginning at the position of the second index. The comparison is case-sensitive and the default locale is used.
The length parameter must be non-negative. If length equals zero (length = 0), then zero is returned.
String Class | String Members | System Namespace | String.Compare Overload List | Int32