RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
StrUtils.ReplaceStr Function

Replaces all occurrences of a substring within a string, using case-sensitive search.

Pascal
function ReplaceStr(const AText: string; const AFromText: string; const AToText: string): string;
C++
AnsiString ReplaceStr(const AnsiString AText, const AnsiString AFromText, const AnsiString AToText);

Use ReplaceStr to replace all occurrences of the substring AFromText with the string AToText, within the string AText. ReplaceStr returns the string obtained after replacement.  

Use ReplaceText to do a case-insensitive replacement.

Note: Both the parameters and the return value are of type string, which is an alias for UnicodeString. To do the replacement in an AnsiString context, use the ReplaceStr function. Also, to do the replacement in a WideString context, use the WideReplaceStr function.
Note: Recursive replacement of substrings is not supported. This means that if the substitution of AToText results in a new match for AFromText, that match is not replaced.
ReplaceStr is the same function as AnsiReplaceStr.  

The StringReplace function is a more general replacement routine, giving case-sensitivity options, as well as the option to decide whether to replace all occurrences or the first occurrence of the substring in the string. 

 

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