- // 过滤HTML标签
- - (NSString *)flattenHTML:(NSString *)html {
- NSScanner *theScanner;
- NSString *text = nil;
- theScanner = [NSScanner scannerWithString:html];
- while ([theScanner isAtEnd] == NO) {
- // find start of tag
- [theScanner scanUpToString:@"<" intoString:NULL] ;
- // find end of tag
- [theScanner scanUpToString:@">" intoString:&text] ;
- // replace the found tag with a space
- //(you can filter multi-spaces out later if you wish)
- html = [html stringByReplacingOccurrencesOfString:
- [ NSString stringWithFormat:@"%@>", text]
- withString:@” “];
- } // while //
- return html;
- }