CorString: CompareEx

CompareEx

Compares substrings of two specified String objects using the specified rules, and returns an integer that indicates their relative position in the sort order.



 Public Function CompareEx(
	  ByRef StrA As String,
	  ByVal IndexA As Long,
	  ByRef StrB As String,
	  ByVal IndexB As Long,
	  ByVal Length As Long,
	  Optional ByVal ComparisonType As StringComparison = StringComparison. Ordinal ) As Long

Parameters

StrA
[ByRef] String. The first string to use in the comparison.
IndexA
[ByVal] Long. The position of the substring within StrA.
StrB
[ByRef] String. The second string to use in the comparison.
IndexB
[ByVal] Long. The position of the substring within StrB.
Length
[ByVal] Long. The maximum number of characters in the substrings to compare.
ComparisonType
[ByVal] Optional. StringComparison. One of the enumeration values that specifies the rules to use in the comparison.  

Default: StringComparison . Ordinal

Return Values

Long -  A 32-bit signed integer that indicates the lexical relationship between StrA and StrB, as shown in the following table
Value Condition
Less than zeroThe substring in the StrA parameter is less than the substring in the StrB parameter.
ZeroThe substrings are equal, or the Length parameter is zero.
Greater than zeroThe substring in StrA is greater than the substring in StrB.

Remarks

The substrings to compare start in StrA at IndexA and in StrB at IndexB. Both IndexA and IndexB are zero-based; that is, the first character in StrA and StrB is at position zero, not position one.

Exceptions

Exception Condition
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 empty, and Length is greater than zero.
ArgumentExceptionComparisonType is not a StringComparison value.
NotSupportedExceptionStringComparison is not supported.

See Also

Project CorLib Overview

Class CorString Overview