开发者

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜