ios去掉html字符串中的html标签的方法
2017-06-22 本文已影响0人
Jack张77
-(NSString*)filterHTML:(NSString*)html
{
NSScanner* scanner = [NSScannerscannerWithString:html];
NSString* text =nil;
while([scannerisAtEnd]==NO)
{
//找到标签的起始位置
[scannerscanUpToString:@"<"intoString:nil];
//找到标签的结束位置
[scannerscanUpToString:@">"intoString:&text];
//替换字符
html = [htmlstringByReplacingOccurrencesOfString:[NSStringstringWithFormat:@"%@>",text]withString:@""];
}
// NSString * regEx = @"<([^>]*)>";
// html = [html stringByReplacingOccurrencesOfString:regEx withString:@""];
returnhtml;
}