Skip to content

Instantly share code, notes, and snippets.

@BlairDuncan
Created April 11, 2010 13:03
Show Gist options
  • Save BlairDuncan/362698 to your computer and use it in GitHub Desktop.
Save BlairDuncan/362698 to your computer and use it in GitHub Desktop.
@implementation CPString(htmlentities)
+ (CPString)stripHtmlEntites:(CPString)aString
{
//FIXME currently only supports decimal entities
// alert([CPString stringWithoutHtmlEntites:@"Montréal"]);
//alert([CPString stringWithoutHtmlEntites:@"Montréal"]);
var matches = aString.match(/&#\d+;?/g);
if(matches)
for(var i = 0; i < matches.length; i++)
{
var replacement = String.fromCharCode((matches[i]).replace(/\D/g,""));
aString = aString.replace(/&#\d+;?/,replacement);
}
return aString;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment