StringCompare Method (String, Int32, String, Int32, Int32, CultureInfo, CompareOptions) |
Compares substrings of two specified
String objects using the specified comparison options and culture-specific information to influence the comparison, and returns an integer that indicates the relationship of the two substrings to each other in the sort order.
Namespace: SystemAssembly: mscorlib (in mscorlib.dll) Version: 4.0.0.0
Syntax public static int Compare(
string strA,
int indexA,
string strB,
int indexB,
int length,
CultureInfo culture,
CompareOptions options
)
Parameters
- strA
- Type: SystemString
The first string to use in the comparison. - indexA
- Type: SystemInt32
The starting position of the substring within strA. - strB
- Type: SystemString
The second string to use in the comparison. - indexB
- Type: SystemInt32
The starting position of the substring within strB. - length
- Type: SystemInt32
The maximum number of characters in the substrings to compare. - culture
- Type: System.GlobalizationCultureInfo
An object that supplies culture-specific comparison information. - options
- Type: System.GlobalizationCompareOptions
Options to use when performing the comparison (such as ignoring case or symbols).
Return Value
Type:
Int32An integer that indicates the lexical relationship between the two substrings, as shown in the following table.ValueConditionLess than zeroThe substring in
strA is less than the substring in
strB.ZeroThe substrings are equal or
length is zero.Greater than zeroThe substring in
strA is greater than the substring in
strB.
Exceptions Exception | Condition |
---|
ArgumentException | options is not a CompareOptions value. |
ArgumentOutOfRangeException | indexA is greater than strA.Length.-or-indexB is greater than strB.Length.-or-indexA, indexB, or length is negative.-or-Either strA or strB is null, and length is greater than zero. |
ArgumentNullException | culture is null. |
See Also