RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.StrScan Function

Returns a pointer to first occurrence of a specified character in a string.

Pascal
function StrScan(const Str: PAnsiChar; Chr: AnsiChar): PAnsiChar; overload;
function StrScan(const Str: PWideChar; Chr: WideChar): PWideChar; overload;
C++
PAnsiChar StrScan(const PAnsiChar Str, AnsiChar Chr);
PWideChar StrScan(const PWideChar Str, WideChar Chr);

StrScan returns a pointer to the first occurrence of Chr in Str. If Chr does not occur in Str, StrScan returns nil (Delphi) or NULL (C++). The null terminator is considered to be part of the string.

Note: If the source string contains international characters, use AnsiStrScan instead.
 

C++ Examples: 

 

/*
The following example uses an edit control and a button on a
form. When the button is clicked, the text in the edit
control is searched for a wildcard (asterisk character).
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  if (StrScan(Edit1->Text.c_str(), '*'))
    ShowMessage("Wildcard found.");
  else
    ShowMessage("Wildcard not found.");
}

 

Delphi Examples: 

{
The following example uses a button on a form. When the
button is clicked, the text is searched for a wildcard
(asterisk character).
}
function HasWildcards(FileName: PChar): Boolean;
{ Return true if file name has wildcards in it }
begin
  HasWildcards := (StrScan(FileName, '*') <> nil) or
    (StrScan(FileName, '?') <> nil);
end;

procedure TForm1.Button1Click(Sender: TObject);
const
  P: PChar = 'C:\Test.* ';
begin
  if HasWildcards(P) then
    ShowMessage('The string has wildcards')
  else
    ShowMessage('The string does not have wildcards');
end;

 

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