DelphiBasics
AnsiContainsText
Function
Returns true if a string contains a substring, case insensitive StrUtils unit
 function AnsiContainsText ( const Haystack, Needle : string ) : Boolean;
Description
The AnsiContainsText function looks for a Needle string in a Haystack string, returning true if it finds it. Otherwise false.
 
It is a Case insensitive command.
Related commands
AnsiContainsStr Returns true if a string contains a substring
AnsiStartsStr Returns true if a string starts with a substring
AnsiEndsStr Returns true if a string ends with a substring
 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 AnsiContainsText 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
  haystack : AnsiString;
begin
  haystack := 'The cat sat on the mat';

  // Note that AnsiContainsText is case insensitive
  if AnsiContainsText(haystack, 'THE')
  then ShowMessage('''THE'' was found')
  else ShowMessage('''THE'' was not found');

  if AnsiContainsText(haystack, 'the')
  then ShowMessage('''the'' was found')
  else ShowMessage('''the'' was not found');
end;
 
end.
Hide full unit code
   'THE' was found
   'the' was found
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page