Remove HTML Tags from an NSString on the iPhone

前端 未结 22 1477
心在旅途
心在旅途 2020-11-22 10:02

There are a couple of different ways to remove HTML tags from an NSString in Cocoa.

One way is to render the string into an

22条回答
  •  不知归路
    2020-11-22 10:35

    This NSString category uses the NSXMLParser to accurately remove any HTML tags from an NSString. This is a single .m and .h file that can be included into your project easily.

    https://gist.github.com/leighmcculloch/1202238

    You then strip html by doing the following:

    Import the header:

    #import "NSString_stripHtml.h"
    

    And then call stripHtml:

    NSString* mystring = @"Hello World!!";
    NSString* stripped = [mystring stripHtml];
    // stripped will be = Hello World!!
    

    This also works with malformed HTML that technically isn't XML.

提交回复
热议问题