views:

590

answers:

5

Hi,

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.

+1  A: 

Can you just use NSMutableString's replaceOccurrencesOfString:withString:options:range: method?

MarkPowell
Using this message force me to define an array with all possible strings to replace which is a very heavy work. However, I'll try to find this array in other programming language and use it in Objective-C
arielcamus
A: 

Hi Arielcamus,

you are not the first with this question. Take a look at this thread:
http://stackoverflow.com/questions/1105169/html-character-decoding-in-objective-c-cocoa

Shingoo
I've read that question before, but this user is asking for numeric HTML entities which are easier to replace. The numeric code is the same and you just have to replace surrounding characters.
arielcamus
+2  A: 

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.

Matt Stevens
A: 

To expand on Matt Stevens answer (since I'm not allowed to comment yet), you don't need to comment out _GTMDevLog, as it is intentionally set up so that you can #define it yourself to whatever you want.

dmaclach
+1  A: 

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

- (NSString *)stringByConvertingHTMLToPlainText;
- (NSString *)stringByDecodingHTMLEntities;
- (NSString *)stringByEncodingHTMLEntities;
- (NSString *)stringWithNewLinesAsBRs;
- (NSString *)stringByRemovingNewLinesAndWhitespace;
Michael Waterfall