Remove HTML Tags from an NSString on the iPhone

前端 未结 22 1643
心在旅途
心在旅途 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:33

    following is the accepted answer, but instead of category, it is simple helper method with string passed into it. (thank you m.kocikowski)

    -(NSString *) stringByStrippingHTML:(NSString*)originalString {
        NSRange r;
        NSString *s = [originalString copy];
        while ((r = [s rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
            s = [s stringByReplacingCharactersInRange:r withString:@""];
        return s;
    }
    

提交回复
热议问题