Delphi Basics
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
 
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
 
 
© CodeGear 2006 - 2007. All rights reserved.  |  Home Page