System.SysUtils.TStringHelper.Compare
Delphi
class function Compare(const StrA: string; const StrB: string): Integer; overload; static; inline;
class function Compare(const StrA: string; const StrB: string; LocaleID: TLocaleID): Integer; overload; static; inline;
class function Compare(const StrA: string; const StrB: string; IgnoreCase: Boolean): Integer; overload; static; inline; //deprecated 'Use same with TCompareOptions';
class function Compare(const StrA: string; const StrB: string; IgnoreCase: Boolean; LocaleID: TLocaleID): Integer; overload; static; inline; //deprecated 'Use same with TCompareOptions';
class function Compare(const StrA: string; const StrB: string; Options: TCompareOptions): Integer; overload; static; inline;
class function Compare(const StrA: string; const StrB: string; Options: TCompareOptions; LocaleID: TLocaleID): Integer; overload; static; inline;
class function Compare(const StrA: string; IndexA: Integer; const StrB: string; IndexB: Integer; Length: Integer): Integer; overload; static; inline;
class function Compare(const StrA: string; IndexA: Integer; const StrB: string; IndexB: Integer; Length: Integer; LocaleID: TLocaleID): Integer; overload; static; inline;
class function Compare(const StrA: string; IndexA: Integer; const StrB: string; IndexB: Integer; Length: Integer; IgnoreCase: Boolean): Integer; overload; static; inline; //deprecated 'Use same with TCompareOptions';
class function Compare(const StrA: string; IndexA: Integer; const StrB: string; IndexB: Integer; Length: Integer; IgnoreCase: Boolean; LocaleID: TLocaleID): Integer; overload; static; inline; //deprecated 'Use same with TCompareOptions';
class function Compare(const StrA: string; IndexA: Integer; const StrB: string; IndexB: Integer; Length: Integer; Options: TCompareOptions): Integer; overload; static; inline;
class function Compare(const StrA: string; IndexA: Integer; const StrB: string; IndexB: Integer; Length: Integer; Options: TCompareOptions; LocaleID: TLocaleID): Integer; overload; static; inline;
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
function | public | System.SysUtils.pas | System.SysUtils | TStringHelper |
Description
Compares two 0-based strings for equality.
Compare is a static class function (calling syntax can be String.Compare(...);
) and returns:
- < 0 if
StrA
sorts beforeStrB
- 0 if
StrA
is the same asStrB
- > 0 if
StrA
sorts afterStrB
var
MyStringA, MyStringB: String;
begin
MyStringA := 'String A';
MyStringB := 'String B';
Writeln(Boolean(String.Compare(MyStringA, MyStringB) = 0));
end.
Output:
FALSE
There are eight Compare overloaded methods:
- The first Compare overloaded method compares
StrA
againstStrB
with case-sensitivity. - The second Compare overloaded method compares
StrA
againstStrB
with specified language and region identifier through theLocaleID
parameter. This method is case-sensitive. - The third Compare overloaded method compares
StrA
againstStrB
with specifiable case-sensitivity through theIgnoreCase
parameter. - The fourth Compare overloaded method compares
StrA
againstStrB
with specifiable case-sensitivity through theIgnoreCase
parameter and with specified language and region identifier through theLocaleID
parameter. - The fifth Compare overloaded method compares
StrA
againstStrB
and allows you to specify from what position in the strings (IndexA
againstIndexB
) to start the comparison, and for what number of characters (Length
). This method is case-sensitive. - The sixth Compare overloaded method compares
StrA
againstStrB
and allows you to specify from what position in the strings (IndexA
againstIndexB
) to start the comparison, and for what number of characters (Length
). This method also allows you to specify the language and region identifier through theLocaleID
parameter. This method is case-sensitive. - The seventh Compare overloaded method compares
StrA
againstStrB
and allows you to specify from what position in the strings (IndexA
againstIndexB
) to start the comparison, and for what number of characters (Length
). This method is user specifiable case-sensitive through theIgnoreCase
parameter. - The eighth Compare overloaded method compares
StrA
againstStrB
and allows you to specify from what position in the strings (IndexA
againstIndexB
) to start the comparison, and for what number of characters (Length
). This method is user specifiable case-sensitive through theIgnoreCase
parameter. This method also allows you to specify the language and region identifier through theLocaleID
parameter.
Note: In some circumstances, Compare can unexpectedly fail on older versions of Windows (prior to Windows 7). For example, failure can result if a string contains a hyphen ("-"), or if the System.SysUtils.TCompareOption coLingIgnoreCase or coDigitAsNumbers is set.
Note: In some circumstances, Compare can fail on older versions of Windows (prior to Windows 7). For example, failure can result if a string contains a hyphen ("-"), or if the System.SysUtils.TCompareOption coLingIgnoreCase or coDigitAsNumbers is set.