RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.StrPos

Returns a pointer to the first occurrence of STR2 in STR1.

StrPos returns a pointer to the first occurrence of Str2 in Str1. If Str2 does not occur in Str1, StrPos returns nil (Delphi) or NULL (C++).

Note: If the source string contains international characters, use AnsiStrPos 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 first
edit control is searched for the text in the second edit control.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  if (StrPos(Edit1->Text.c_str(), Edit2->Text.c_str()))
    ShowMessage("Substring found.");
  else
    ShowMessage("Substring not found.");
}

 

Delphi Examples: 

{
The following example uses two edit controls and a button on
a form. When the button is clicked, the text in the first
edit control is searched for the text in the second edit control.
}
procedure TForm1.Button1Click(Sender: TObject);
begin
  if StrPos(PChar(Edit1.Text), PChar(Edit2.Text)) <> nil then
    ShowMessage('Substring found')
  else
    ShowMessage('Substring not found');
end;

 

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