You are on page 1of 1

StringReplace

Function Replace one or more substrings found within a string


SysUtils unit

function StringReplace ( const SourceString, OldPattern,


NewPattern : string; Flags : TReplaceFlags ) : string;

Description

The StringReplace function replaces the first or all occurences of a


substring OldPattern in SourceString with NewPattern according to Flags settings.

The changed string is returned.

The Flags may be none, one, or both of these set values:

rfReplaceAll : Change all occurrences


rfIgnoreCase : Ignore case when searching

These values are specified in square brackets, as in the example.

Example code : Change a to THE in a sentence

var
before, after : string;

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

after := StringReplace(before, ' a ', ' THE ',


[rfReplaceAll,
rfIgnoreCase]); ShowMessage('Before = '+before);
ShowMessage('After = '+after);
end;
Show full unit code

Before = This is a way to live A big life


After = This is THE way to live THE big life

You might also like