find_replace

Definition: sequence res = find_replace(object needle, sequence haystack, object replacement, integer max_replacements=0)
Description: Finds needle in haystack, and replaces all or upto max_replacements occurrences with replacement.

needle: an object to search and perhaps replace.
haystack: a sequence to be inspected.
replacement: an object to substitute for instances of needle.
max_replacements: number of items to replace, or 0 to replace all occurrences

Returns a sequence, the modified haystack.
Comments: Replacements will not be made recursively on the part of haystack that was already changed.

If max is 0 or less, any occurrence of needle in haystack will be replaced by replacement.
Otherwise, only the first max_replacements occurrences are replaced.

This routine is defined in builtins/findrepl.e and is provided only for compatibility with OpenEuphoria.
Example:
s = find_replace('b', "The batty book was all but in Corba.", 'c', 0)   -- s is "The catty cook was all cut in Corca."
s = find_replace('/', "/euphoria/demo/unix", '\\', 2)                   -- s is "\\euphoria\\demo/unix"
s = find_replace("theater", { "the", "theater", "theif" }, "theatre")   -- s is { "the", "theatre", "theif" }