RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.StrIComp Function

Compares two strings without case sensitivity.

Pascal
function StrIComp(const Str1: PAnsiChar; const Str2: PAnsiChar): Integer; overload;
function StrIComp(const Str1: PWideChar; const Str2: PWideChar): Integer; overload;
C++
int StrIComp(const PAnsiChar Str1, const PAnsiChar Str2);
int StrIComp(const PWideChar Str1, const PWideChar Str2);

Call StrIComp to compare two strings without case sensitivity. StrIComp returns a value greater than 0 if Str1 > Str2, less than 0 if Str1 < Str2, and returns 0 if the strings are equal except for differences in case. 

When working with international characters, use AnsiStrIComp instead.  

C++ Examples: 

 

/*
The following example uses two edit controls and a button on
a form. When the button is clicked, the text in the edit
controls is compared case-insensitively.
*/
#include <memory>       //for STL auto_ptr class

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  std::auto_ptr<char> szResult(new char[Edit1->Text.Length() + Edit2->Text.Length() + 20]);
  int iResult = StrIComp(Edit1->Text.c_str(), Edit2->Text.c_str());

  StrCopy(szResult.get(), Edit1->Text.t_str());
  if (iResult < 0)
    StrCat(szResult.get(), " is less than ");
  else if (iResult > 0)
    StrCat(szResult.get(), " is greater than ");
  else
    StrCat(szResult.get(), " is equal to ");
  StrCat(szResult.get(), Edit2->Text.t_str());
  ShowMessage(AnsiString(szResult.get()));
}

 

Delphi Examples: 

{
The following example uses two edit controls and a button on
a form. When the button is clicked, the text in the edit
controls is compared case-insensitively.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  Msg: string;
  CompResult: Integer;
begin
  Msg := Edit1.Text;
  CompResult := StrIComp(PChar(Edit1.Text), PChar(Edit2.Text));
  if CompResult < 0 then
    Msg := Msg + ' is less than '
  else if CompResult > 0 then
    Msg := Msg + ' is greater than '
  else
    Msg := Msg + ' is equal to ';
  Msg := Msg + Edit2.Text;
  ShowMessage(Msg);
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!