System.SysUtils.StringReplace

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function StringReplace(const Source, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;

C++

extern DELPHI_PACKAGE System::UnicodeString __fastcall StringReplace(const System::UnicodeString Source, const System::UnicodeString OldPattern, const System::UnicodeString NewPattern, TReplaceFlags Flags)/* overload */;

Properties

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

Description

Replaces occurrences of a substring within a string.

StringReplace replaces occurrences of the substring specified by OldPattern with the substring specified by NewPattern in the string Source.

Flags is a TReplaceFlags type parameter. If rfIgnoreCase is set, the replacement is case-insensitive; otherwise case is significant. If rfReplaceAll is on, all occurrences of OldPattern are replaced; if not, only the first occurrence is replaced.

Note: This function is designed for UnicodeString variables. To work with AnsiString variables, use the System.AnsiStrings.StringReplace function. To work with WideString variables, use the System.WideStrUtils.WideStringReplace function.

Note: Recursive replacement of substrings is not supported. This means that if the substitution of OldPattern results in a new match for NewPattern, that match is not replaced.

To replace all occurrences of the substring within the string, you may also use the ReplaceStr function to do a case-sensitive search, or ReplaceText to do a case-insensitive search.

See Also