HTML character decoding in Objective-C / Cocoa Touch

treznik picture treznik · Jul 9, 2009 · Viewed 93.4k times · Source

First of all, I found this: Objective C HTML escape/unescape, but it doesn't work for me.

My encoded characters (come from a RSS feed, btw) look like this: &

I searched all over the net and found related discussions, but no fix for my particular encoding, I think they are called hexadecimal characters.

Answer

Michael Waterfall picture Michael Waterfall · May 16, 2010

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

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