Built-in (or external framework) method in the iOS sdk to convert a string with HTML &xxx; sequences to plain characters?
Is there a built-in way in the iOS sdk to take an NSString containing HTML sequences
& amp;, & nbsp;, & lt; (spaces added to avoid markdown开发者_如何学编程 interpretation)
etc., and translate those to '&', ' ', '<' ? My string contains international UTF8 characters so I can't convert to ascii.
As Michael Waterfall has commented on other, similar questions, there is no built-in function available, but have a look at his solution which is a new category for NSString.
It defines the following new methods, especially stringByDecodingHTMLEntities
:
- (NSString *)stringByConvertingHTMLToPlainText;
- (NSString *)stringByDecodingHTMLEntities;
- (NSString *)stringByEncodingHTMLEntities;
- (NSString *)stringWithNewLinesAsBRs;
- (NSString *)stringByRemovingNewLinesAndWhitespace;
精彩评论