DelphiBasics
TReplaceFlags
Type
Defines options for the StringReplace routine SysUtils unit
  type TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase);
Description
The TReplaceFlags enumeration type gives the options for the StringReplace routine :
 
rfReplaceAll  Replace all find occurences
rfIgnoreCase  Find ignores case
Related commands
StringReplace Replace one or more substrings found within a string
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

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




 
Example code : Change all occurences regardless of case
// 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
  SysUtils,   // Unit containing the TReplaceFlags 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
  before, after : string;
  options       : TReplaceFlags;

begin
  // Try to replace all occurrences of a or A to THE
  before := 'This is a way to live A big life';

  // Set the options to change all occurences regardless of case
  options := [rfReplaceAll, rfIgnoreCase];

  // Now change 'a' or 'A' to 'THE' throughout
  after  := StringReplace(before, ' a ', ' THE ', options);

  // Show the before and after
  ShowMessage('Before = '+before);
  ShowMessage('After  = '+after);
end;
 
end.
Hide full unit code
   This is a way to live A big life
   This is THE way to live THE big life
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page