System.SysUtils.TStringHelper.Compare

From RAD Studio API Documentation
Jump to: navigation, search

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 before StrB
  • 0 if StrA is the same as StrB
  • > 0 if StrA sorts after StrB
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 against StrB with case-sensitivity.
  • The second Compare overloaded method compares StrA against StrB with specified language and region identifier through the LocaleID parameter. This method is case-sensitive.
  • The third Compare overloaded method compares StrA against StrB with specifiable case-sensitivity through the IgnoreCase parameter.
  • The fourth Compare overloaded method compares StrA against StrB with specifiable case-sensitivity through the IgnoreCase parameter and with specified language and region identifier through the LocaleID parameter.
  • The fifth Compare overloaded method compares StrA against StrB and allows you to specify from what position in the strings (IndexA against IndexB) to start the comparison, and for what number of characters (Length). This method is case-sensitive.
  • The sixth Compare overloaded method compares StrA against StrB and allows you to specify from what position in the strings (IndexA against IndexB) to start the comparison, and for what number of characters (Length). This method also allows you to specify the language and region identifier through the LocaleID parameter. This method is case-sensitive.
  • The seventh Compare overloaded method compares StrA against StrB and allows you to specify from what position in the strings (IndexA against IndexB) to start the comparison, and for what number of characters (Length). This method is user specifiable case-sensitive through the IgnoreCase parameter.
  • The eighth Compare overloaded method compares StrA against StrB and allows you to specify from what position in the strings (IndexA against IndexB) to start the comparison, and for what number of characters (Length). This method is user specifiable case-sensitive through the IgnoreCase parameter. This method also allows you to specify the language and region identifier through the LocaleID 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.

See Also