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
StrAsorts beforeStrB - 0 if
StrAis the same asStrB - > 0 if
StrAsorts 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
StrAagainstStrBwith case-sensitivity. - The second Compare overloaded method compares
StrAagainstStrBwith specified language and region identifier through theLocaleIDparameter. This method is case-sensitive. - The third Compare overloaded method compares
StrAagainstStrBwith specifiable case-sensitivity through theIgnoreCaseparameter. - The fourth Compare overloaded method compares
StrAagainstStrBwith specifiable case-sensitivity through theIgnoreCaseparameter and with specified language and region identifier through theLocaleIDparameter. - The fifth Compare overloaded method compares
StrAagainstStrBand allows you to specify from what position in the strings (IndexAagainstIndexB) to start the comparison, and for what number of characters (Length). This method is case-sensitive. - The sixth Compare overloaded method compares
StrAagainstStrBand allows you to specify from what position in the strings (IndexAagainstIndexB) to start the comparison, and for what number of characters (Length). This method also allows you to specify the language and region identifier through theLocaleIDparameter. This method is case-sensitive. - The seventh Compare overloaded method compares
StrAagainstStrBand allows you to specify from what position in the strings (IndexAagainstIndexB) to start the comparison, and for what number of characters (Length). This method is user specifiable case-sensitive through theIgnoreCaseparameter. - The eighth Compare overloaded method compares
StrAagainstStrBand allows you to specify from what position in the strings (IndexAagainstIndexB) to start the comparison, and for what number of characters (Length). This method is user specifiable case-sensitive through theIgnoreCaseparameter. This method also allows you to specify the language and region identifier through theLocaleIDparameter.
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.