CompareStr (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

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'.

Code

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 less than 0. }
  Edit1.Text := InttoStr(I);
  if I <> 0 then
    MessageDlg('The strings are not equal', mtWarning, [mbOK], 0)
end;

Uses

See Also