Skip to content

ReplaceStr ​

ReplaceStr replaces all instances of the string specified by AFromText in the source string AText, with the string AToText, and returns this amended value as the resulting string.

The function is fully case sensitive.

For a function that is not case sensitive, use the ReplaceText routine. Please refer to ReplaceText.

Declaration: Function ReplaceStr(const AText, AFromText, AToText : string) : string;

Examples are detailed below - including an example showing how this function handles case.

pascal
procedure ScriptEvent(var Value:Variant);
var
  Str1, Str2, Str3, Str4 : string;
begin
  Str1 := 'Mary had a little lamb.'
  Str2 := 'little'
  Str3 := 'gigantic 3-legged'
  Str4 := ReplaceStr(Str1, Str2, Str3);         //The text will change
  LogInfo('The text has gone from '''+Str1+''' to '''+Str4+'''');

  Str1 := 'Jack and Jill went up the hill.'
  Str2 := 'HILL'
  Str3 := 'mountain'
  Str4 := ReplaceStr(Str1, Str2, Str3);         //The text will not be changed
  LogInfo('The text has gone from '''+Str1+''' to '''+Str4+'''');
  LogInfo('');

end;

The resulting entries in the log are as follows.

Please also review the StuffString function StuffString.