asp.net.ph

String.Compare Method ( String, Int32, String, Int32, Int32, Boolean, CultureInfo )

System Namespace   String Class


Compares substrings of two specified String objects, ignoring or honoring their case, and honoring culture-specific information about their formatting.

[ VB ]
<Serializable>
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, _
   ByVal ignoreCase As Boolean, _
   ByVal culture As CultureInfo _
) As Integer

[ C# ]
[ Serializable ]
public static int Compare (
   string strA,
   int indexA,
   string strB,
   int indexB,
   int length,
   bool ignoreCase,
   CultureInfo culture
);

[ C++ ]
[ Serializable ]
public: static int Compare (
   String* strA,
   int indexA,
   String* strB,
   int indexB,
   int length,
   bool ignoreCase,
   CultureInfo* culture
);

[ JScript ]
public Serializable
static function Compare (
   strA : String,
   indexA : int,
   strB : String,
   indexB : int,
   length : int,
   ignoreCase : Boolean,
   culture : CultureInfo
) : int;

Parameters

strA
The first String.
indexA
The position of the substring within strA.
strB
The second String.
indexB
The position of the substring within the strB.
length
The maximum number of characters in the substrings to compare.
ignoreCase
A Boolean indicating a case-sensitive or insensitive comparison. ( true indicates a case-insensitive comparison. )
culture
A CultureInfo object that supplies culture-specific formatting information.

Return Value

An integer indicating the lexical relationship between the two comparands.

Value Type Condition
Less than zero The substring in strA is less than the substring in strB.
Zero The substrings are equal, or length is zero.
Greater than zero The substring in strA is greater than the substring in strB.

Exceptions


Exception Type Condition
ArgumentNullException culture is a null reference ( Nothing in Visual Basic ).
ArgumentOutOfRangeException Either index is outside the series of characters to be compared.

-or-

length is negative.


Remarks

culture specifies a CultureInfo object, which provides culture-specific information that can affect the comparison. length cannot be negative.

The number of characters compared is the lesser of the length of strA less indexA, the length of strB less indexB, and length.

By definition, any String, including the empty string, compares greater than a null reference; and two null references compare equal to each other.

See Also

String Members   String.Compare Overload List   Int32   CompareOrdinal   CompareTo Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph