Overload List
| # | Signature | Description |
|---|---|---|
| 1 | function Replace(const OldPattern, NewPattern: Substring): Substring; overload; | Every non-overlapping occurrence of OldPattern replaced by NewPattern, left to right, ordinal. |
| 2 | function Replace(const OldPattern, NewPattern: string): Substring; overload; | |
| 3 | function Replace(const OldPattern, NewPattern: string; const ReplaceFlags: TReplaceFlags): Substring; overload; | Replaces OldPattern by NewPattern, ordinal: the first occurrence, or every occurrence with rfReplaceAll. |
Overload 1: function Replace(const OldPattern, NewPattern: Substring): Substring; overload;
Every non-overlapping occurrence of OldPattern replaced by NewPattern, left to right, ordinal.
Returns: Substring - The new value; with an empty OldPattern or no occurrence, the text unchanged, as a part.
Every text kind for both patterns, and Char for single characters.
Replacing every occurrence.
uses Substr;
procedure Example;
begin
Assert(Substring('a-b-c').Replace('-', '+') = 'a+b+c');
end;
Overload 2: function Replace(const OldPattern, NewPattern: string): Substring; overload;
| # | Name | Type | Description |
|---|---|---|---|
| 1 | OldPattern | string | |
| 2 | NewPattern | string |
Returns: Substring
Overload 3: function Replace(const OldPattern, NewPattern: string; const ReplaceFlags: TReplaceFlags): Substring; overload;
Replaces OldPattern by NewPattern, ordinal: the first occurrence, or every occurrence with rfReplaceAll.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | OldPattern | string | |
| 2 | NewPattern | string | |
| 3 | ReplaceFlags | TReplaceFlags |
Returns: Substring - The new value.
Every text kind for both patterns. rfIgnoreCase raises ESubstringCaseError: ReplaceLinguistic ignores case by the locale, ReplaceAscii by A to Z only. Note: This routine compares the code units ordinally, case-sensitive and the same under every locale, and does not handle locale specific char handling, but it is 6.7 to 85 times faster than its ReplaceLinguistic alternative.
The first occurrence, and every occurrence.
uses Substr, System.SysUtils;
procedure Example;
begin
Assert(Substring('a.b.c').Replace('.', '/', []) = 'a/b.c');
Assert(Substring('a.b.c').Replace('.', '/', [rfReplaceAll]) = 'a/b/c');
end;