AmpScript – replace special characters

Problem:
I had content being inserted by personalization ( %%CONTENT%%) into the body of an email. The content at times contained some special characters like em-dashes and en-dashes, and those characters don’t always render properly in some email clients.

The solution was to look for those characters and REPLACE them with their HTML entity.

First, create a varible.
VAR @content
Then set the variable to the value of the “CONTENT” field in the database/list.
SET @content = CONTENT

Then use the REPLACE function to find and replace:

SET @content = REPLACE(@content,CHAR(8212),’—’)
SET @content = REPLACE(@content,CHAR(8211),’–’)

Thank you for reading!

It's only fair to share...Tweet about this on Twitter
Twitter
Share on Facebook
Facebook
Email this to someone
email

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.