ReplaceList Function

The ReplaceList function is a simpler way of replacing characters in a string rather than using nested Replace functions. It allows you to search for string values and replace them with another string value.

Syntax:

                    

ReplaceList(1,2,3)
1 = String value that you want to search and replace values in (can be a variable)
2 = Replacement string
3 = Search values to look for in 1 above

                

Example:

                    

%%[ 
var @string
set @string = “AAABBBCCCDDD”
]%%
%%=ReplaceList(@string, ‘X’, ‘A’, ‘B’, ‘C’, ‘D’)=%%

                

Output:

XXXXXXXXXXXX

Explanation:

In the AMPscript above, first we are declaring the variables using the var function. Then defining the @string variable as the string: “AAABBBCCCDDD”

The ReplaceList function is using the string of “AAABBBCCCDDD” as what we want to search. The “X” string is what we will be using to replace the values found (“A”, “B”, “C”, and “D”). In other words, any values that match “A”, “B”, “C”, and “D” will be replaced by “X.”

The output of that value is “XXXXXXXXXXXX” since we replaced all “A”, “B”, “C”, and “D” values with “X”

Leave a Reply

Your email address will not be published. Required fields are marked *