去掉字符串中的html标签的方法

 

 1 -(NSString *)filterHTML:(NSString *)html
 2 {
 3     NSScanner * scanner = [NSScanner scannerWithString:html];
 4     NSString * text = nil;
 5     while([scanner isAtEnd]==NO)
 6     {
 7         //找到标签的起始位置
 8         [scanner scanUpToString:@"<" intoString:nil];
 9         //找到标签的结束位置
10         [scanner scanUpToString:@">" intoString:&text];
11         //替换字符
12         html = [html stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@>",text] withString:@""];
13     }
14     //    NSString * regEx = @"<([^>]*)>";
15     //    html = [html stringByReplacingOccurrencesOfString:regEx withString:@""];
16     return html;
17 }

 

posted on 2015-12-14 16:32  codemaker313  阅读(433)  评论(0编辑  收藏  举报

导航