The Replace function is a way of replacing characters in a string — similar to the ReplaceList function but applies to one string value. It allows you to search for string values and replace them with another string value. A good use case is to replace symbols with the ASCII code to escape it.
Replace (1,2,3) 1 = String value that you want to search and replace values in (can be a variable) 2 = Replacement string 3 = String used as replacement
%%[ var @emailaddress set @emailaddress = “email@example.com” ]%% %%=Replace(@emailaddress, ‘+’, ‘+’)=%%
In the AMPscript above, first we are declaring the variables using the
var function by using the email address. Then defining the
@emailaddress variable with the string value for the email address we are using in this example.
We want to
Replace function to escape out the + symbol as this can cause issues, i.e. when passing that value through a URL: “firstname.lastname@example.org”. The
Replace function looks for the + symbol and replaces it with “+” which is the ASCII version of the + symbol.
The output of that value is “email@example.com” and renders correctly with the plus when outputted on to a Cloud page, for example.