Remove HTML Tags from an NSString on the iPhone

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

    You can use like below

    -(void)myMethod
     {
    
     NSString* htmlStr = @"html";
     NSString* strWithoutFormatting = [self stringByStrippingHTML:htmlStr];
    
     }
    
     -(NSString *)stringByStrippingHTML:(NSString*)str
     {
       NSRange r;
       while ((r = [str rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location     != NSNotFound)
      {
         str = [str stringByReplacingCharactersInRange:r withString:@""];
     }
      return str;
     }
    

提交回复
热议问题