Home > Actionscript > Replace HTML encoded characters with their original ones

Replace HTML encoded characters with their original ones

February 12th, 2009

Just a simple regular expression to replace all HTML encoded characters with their original ones.

var testString:String = "This is a test with a – character and a ’";
testString = testString.replace(/&#([0-9]+);/g, replaceCharacters);
 
private function replaceCharacters(...args):String
{
	return String.fromCharCode(parseInt(args[1]));
}

Actionscript

  1. July 5th, 2009 at 17:33 | #1

    Check out this hack, also does the trick:

    private function replaceCharacters(str:String):String
    {
    return new XMLDocument(str).firstChild.nodeValue;
    }

  2. December 10th, 2011 at 18:05 | #2

    That’s truly exciting. This introduced i am two or three thoughts and then I’ll be posting these products for my web-site finally. I’m just book-marking your blog and also Soon we will be back. Thank you!

  1. No trackbacks yet.