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]));
}

Bernard 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;
    }

  1. No trackbacks yet.