RAD Studio VCL Reference
|
Compares two strings case sensitively.
function CompareStr(const S1: string; const S2: string): Integer; overload; function CompareStr(const S1: string; const S2: string; LocaleOptions: TLocaleOptions): Integer; overload;
int CompareStr(const AnsiString S1, const AnsiString S2); int CompareStr(const AnsiString S1, const AnsiString S2, TLocaleOptions LocaleOptions);
CompareStr compares S1 to S2, with case-sensitivity. The return value is less than 0 if S1 is less than S2, 0 if S1 equals S2, or greater than 0 if S1 is greater than S2. The compare operation is based on the 8-bit ordinal value of each character and is not affected by the current locale.
C++ Examples:
/* The following code compares String1, 'STEVE', to String2, 'STEVe'. Note that CompareStr returns a number less than 0 because the value of 'e' is greater than the value of 'E'. */ void __fastcall TForm1::Button1Click(TObject *Sender) { AnsiString String1 = "STEVE"; AnsiString String2 = "Steve"; int I = CompareStr(String1, String2); // the value of I is < 0 Edit1->Text = IntToStr(I); if (I != 0) ShowMessage ("The strings are not equal"); }
Delphi Examples:
{ The following code compares String1, 'STEVE', to String2, 'STEVe'. Note that CompareStr returns a number less than 0 because the value of 'e' is greater than the value of 'E'. } procedure TForm1.Button1Click(Sender: TObject); var String1, String2 : string; I : Integer; begin String1 := 'STEVE'; String2 := 'STEVe'; I := SysUtils.CompareStr(String1, String2); { the value of I is < 0 } Edit1.Text := InttoStr(I); if I <> 0 then MessageDlg('The strings are not equal', mtWarning, [mbOK], 0) end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|