DelphiBasics
AnsiMatchStr
Function
Returns true if a string exactly matches one of a list of strings StrUtils unit
 function AnsiMatchStr ( const Source : string; const StringList : array of string ) : Boolean;
Description
The AnsiMatchStr function checks to see if any of the strings in StringList exactly match the Source string.
 
If any match, true is found, otherwise false is returned.
 
The string list can be specified as a square bracket delimited list, as in the example, or as an array of strings.
 
It is a Case sensitive command.
Related commands
AnsiIndexStr Compares a string with a list of strings - returns match index
AnsiPos Find the position of one string in another
StrScan Searches for a specific character in a constant string
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 Download this web site as a Windows program.




 
Example code : A simple example
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  StrUtils,   // Unit containing the AnsiMatchStr command
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

var
  source : AnsiString;
begin
  source := 'Henry';   // The string to match

  // Note that AnsiMatchStr is case sensitive
  // We use a hard coded constant string array
  if AnsiMatchStr(source, ['BRIAN', 'JIM', 'HENRY'])
  then ShowMessage('First match was successful')
  else ShowMessage('First match was not successful');

  // Note that arrays start at 0
  if AnsiMatchStr(source, ['Brian', 'Jim', 'Henry'])
  then ShowMessage('Second match was successful')
  else ShowMessage('Second match was not successful');
end;
 
end.
Hide full unit code
   First match was not successful
   Second match was successful
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page