From RAD Studio API Documentation
Jump to: navigation, search


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


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


Type Visibility Source Unit Parent
function public
System.AnsiStrings System.AnsiStrings


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 S.

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

Note: This function is designed for AnsiString variables. To work with UnicodeString variables, use the System.SysUtils.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