Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C HTML escape/unescape

Wondering if there is an easy way to do a simple HTML escape/unescape in Objective C. What I want is something like this psuedo code:

NSString *string = @"<span>Foo</span>"; [string stringByUnescapingHTML]; 

Which returns

<span>Foo</span> 

Hopefully unescaping all other HTML entities as well and even ASCII codes like Ӓ and the like.

Is there any methods in Cocoa Touch/UIKit to do this?

like image 680
Alex Wayne Avatar asked Mar 18 '09 18:03

Alex Wayne


1 Answers

Check out my NSString category for XMLEntities. There's methods to decode XML entities (including all HTML character references), encode XML entities, stripping tags and removing newlines and whitespace from a string:

- (NSString *)stringByStrippingTags; - (NSString *)stringByDecodingXMLEntities; // Including all HTML character references - (NSString *)stringByEncodingXMLEntities; - (NSString *)stringWithNewLinesAsBRs; - (NSString *)stringByRemovingNewLinesAndWhitespace; 
like image 56
Michael Waterfall Avatar answered Sep 27 '22 20:09

Michael Waterfall