This built-in string predicate replaces all occurences of the second argument, string_to_replace, with the value of the last argument, string_replace_with. The string that is changed is the first argument. With replace/3 it is also possible to remove all occurences of string_to_replace by specifing a null atom as the value of the last argument.
see also: &/2 delete/3 expand_sq/1insert/3 is/2 substring/3 string_list/2 to_lower/1 to_string/2 to_upper/1 trim/1 triml/1 trimr/1 working with strings
| Examples | |
| X is_string replace('abcdef', 'a', 'x'). | variable X is unified with the string 'xbcdef' |
| X is_string replace('abacadaeaf', 'a', ''). | variable X is unified with the string 'bcdef', all occurences of 'a' are removed from 'abacadaeaf' because the third argument is the null atom |
| Exceptions | |
| The parameter is an empty variable | an instantiation_error exception is thrown |