Skip to content

Instantly share code, notes, and snippets.

@asimpson
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asimpson/4de93d0f64bd8953b506 to your computer and use it in GitHub Desktop.
Save asimpson/4de93d0f64bd8953b506 to your computer and use it in GitHub Desktop.
Simple method that takes a NSString with HTML entities in it, and cleans that string of those entities.
- (NSString *) format: (NSString *)string {
NSAttributedString *formattedString = [[NSAttributedString alloc] initWithData:[string dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]} documentAttributes:nil error:nil];
return formattedString.string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment