substitute

Definition: string text = substitute(string text, string s, string r)
Description: Replace all instances of s in text with r.
Comments: Ideal for extensive text manipulation, eg re-indenting html or stripping tags to leave plain text.

Very long strings that need thousands of replacements are broken up into thousands of chunks and re-assembled once at the end, which makes this far more efficient than an "in situ" operation, since individual characters (in particular the last few) are moved just twice rather than thousands of times.

The OpenEuphoria match_replace() routine offers similar but less efficient functionality, especially when the lengths of s and r differ. The previous replace_all() routine of OpenEuphoria has been deprecated in favour of match_replace(). The phix implementation of substitute() as found in builtins\substitute.e and reproduced below should work on OpenEuphoria, once all the string types are replaced with sequence types.
Example:
?substitute("abracadabra", "ra", "X")       -- displays "abXcadabX"
?substitute("abracadabra", "a", "")         -- displays "brcdbr"
See Also: join, tagset