当前位置:Gxlcms >
html代码 >
去掉NSString中的HTML标签_html/css_WEB-ITnose
去掉NSString中的HTML标签_html/css_WEB-ITnose
时间:2021-07-01 10:21:17
帮助过:43人阅读
-(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:@""];
}
NSString * regEx = @"<([^>]*)>";
html = [html stringByReplacingOccurrencesOfString:regEx withString:@""];
return html;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。