System.SysUtils.TStringHelper.Replace

From Appmethod Libraries
Jump to: navigation, search

Object Pascal

function Replace(OldChar: Char; NewChar: Char): string; overload;
function Replace(OldChar: Char; NewChar: Char; ReplaceFlags: TReplaceFlags): string; overload;
function Replace(const OldValue: string; const NewValue: string): string; overload;
function Replace(const OldValue: string; const NewValue: string; ReplaceFlags: TReplaceFlags): string; overload;

Properties

Type Visibility Source Unit Parent
function public System.SysUtils.pas System.SysUtils TStringHelper

Description

Replaces an old character or string with a new given character or string.

var
  MyString: String;

begin
  MyString := 'This is a string.';

  Writeln(MyString.Replace('a', 'one'));
  Writeln(MyString.Replace('a', '1'));
end.

Output:

This is one string.
This is 1 string.

There are four Replace overloaded methods. The first two of them replace only characters while the third and fourth ones replace strings. The ReplaceFlags parameter is introduced in order for you to use flags such as rfIgnoreCase or rfReplaceAll.

See Also