Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C: How to replace HTML entities? [duplicate]

I'm getting text from Internet and it contains html entities (i.e. ó = ó). I want to show this text into a custom iPhone cell.

I've tried to use a UIWebView into my custom cell but I prefer to use a multiline UILabel. The problem is I can't find any way of replacing these HTML entities.

like image 653
arielcamus Avatar asked Mar 02 '10 16:03

arielcamus


2 Answers

Check out my NSString category for HTML. Here are the methods available:

- (NSString *)stringByConvertingHTMLToPlainText;
- (NSString *)stringByDecodingHTMLEntities;
- (NSString *)stringByEncodingHTMLEntities;
- (NSString *)stringWithNewLinesAsBRs;
- (NSString *)stringByRemovingNewLinesAndWhitespace;
like image 155
Michael Waterfall Avatar answered Sep 24 '22 07:09

Michael Waterfall


Google Toolbox for Mac includes an iPhone-compatible NSString addition that will do this for you: gtm_stringByUnescapingFromHTML defined in GTMNSString+HTML.h and GTMNSString+HTML.m. If you comment out the calls to _GTMDevLog and #import "GTMDefines.h" in the .m you only need to add these two files to your project.

like image 22
Matt Stevens Avatar answered Sep 21 '22 07:09

Matt Stevens