RAD Studio VCL Reference
AnsiStrings.StringReplace Function

Replaces occurrences of a substring within a string.

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

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: The parameters S, OldPattern, NewPattern, and the return value are of type AnsiString. To do the replacement in a UnicodeString context, use the StringReplace function. Also, to do the replacement in a WideString context, use the 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. 


Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!