Substring.Compare Method

Overload List

#SignatureDescription
1class function Compare(const StrA: Substr.Substring; const IndexA: Integer; const StrB: Substr.Substring; const IndexB, Length: Integer): Integer; overload; static;Compares Length characters of StrA from IndexA with Length characters of StrB from IndexB, ordinal.
2class function Compare(const StrA: Substr.Substring; const IndexA: Integer; const StrB: string; const IndexB, Length: Integer): Integer; overload; static;
3class function Compare(const L, R: Substring): Integer; overload; static;Ordinal comparison by UTF-16 code unit.
4class function Compare(const L: Substring; const R: string): Integer; overload; static;
5class function Compare(const StrA: string; const IndexA: Integer; const StrB: Substr.Substring; const IndexB, Length: Integer): Integer; overload; static;
6class function Compare(const L: string; const R: Substring): Integer; overload; static;

Overload 1: class function Compare(const StrA: Substr.Substring; const IndexA: Integer; const StrB: Substr.Substring; const IndexB, Length: Integer): Integer; overload; static;

Compares Length characters of StrA from IndexA with Length characters of StrB from IndexB, ordinal.

#NameDescription
1IndexA

The first character of StrA compared, 0-based.

2IndexB

The first character of StrB compared, 0-based.

3Length

The characters compared; each window must lie inside its text, else ESubstringRangeError is raised.

Returns: Integer - 0 when equal, else the difference of the first differing characters.

Remarks:

Note: This routine compares the code units ordinally, case-sensitive and the same under every locale, and does not handle locale specific char handling, but it is 6.4 to 8.8 times faster than its CompareLinguistic alternative.

Examples

Comparing windows.

uses Substr;

procedure Example;
begin
    Assert(Substring.Compare(Substring('xabc'), 1, 'abc', 0, 3) = 0);
end;

Overload 2: class function Compare(const StrA: Substr.Substring; const IndexA: Integer; const StrB: string; const IndexB, Length: Integer): Integer; overload; static;

#NameTypeDescription
1StrASubstr.Substring
2IndexAInteger
3StrBstring
4IndexBInteger
5LengthInteger

Returns: Integer

Overload 3: class function Compare(const L, R: Substring): Integer; overload; static;

Ordinal comparison by UTF-16 code unit.

#NameTypeDescription
1LSubstring
2RSubstring

Returns: Integer - 0 when equal; else the difference of the first differing characters, or, when one text is a prefix of the other, the difference of the lengths.

Remarks:

Either operand may be a string. An embedded #0 is a character like any other. Note: This routine compares the code units ordinally, case-sensitive and the same under every locale, and does not handle locale specific char handling, but it is 19 to 153 times faster than its CompareLinguistic alternative.

Examples

The difference of the first differing characters, and of the lengths.

uses Substr;

procedure Example;
begin
    Assert(Substring.Compare(Substring('a'), 'b') = -1);
    Assert(Substring.Compare(Substring('abc'), 'ab') = 1);
    Assert(Substring.Compare(Substring('abc'), 'abc') = 0);
end;

Overload 4: class function Compare(const L: Substring; const R: string): Integer; overload; static;

#NameTypeDescription
1LSubstring
2Rstring

Returns: Integer

Overload 5: class function Compare(const StrA: string; const IndexA: Integer; const StrB: Substr.Substring; const IndexB, Length: Integer): Integer; overload; static;

#NameTypeDescription
1StrAstring
2IndexAInteger
3StrBSubstr.Substring
4IndexBInteger
5LengthInteger

Returns: Integer

Overload 6: class function Compare(const L: string; const R: Substring): Integer; overload; static;

#NameTypeDescription
1Lstring
2RSubstring

Returns: Integer