去掉字符串中HTML标签的方法
2017-01-10 本文已影响0人
特喵了个咪的猫
- (NSString *)filterHTML:(NSString *)html{
NSScanner *scanner = [NSScanner scannerWithString:html];
NSString *text = nil;
while ([scanner isAtEnd] == NO) {
//找到标签的起始位置
[scanner scanUpToString:@"<" intoString:nil];
//找到标签的结束位置
[scanner scanUpToString:@">" intoString:&text];
//替换字符
html = [html stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@>",text] withString:@""];
}
return html;
}
self.label.text = [self filterHTML:self.xxModel.XXX];