去掉html的所有标签,但  去不掉,求解

后台录入html格式的,请求服务器,解析,拿到的数据全是html类型的字符串,通过网上的一些方法去掉了一些<,>,/p等标签和特殊字符,但是唯独 开头空行 和 &nbsp;去不掉,请教一下

试试这个方法

- (NSString *)flattenHTML:(NSString *)html {

NSScanner *theScanner;

NSString *text = nil;

theScanner = NSScanner scannerWithString:html];

while ( == NO) {

// find start of tag

;

// find end of tag

;

// replace the found tag with a space

//(you can filter multi-spaces out later if you wish)

html = [html stringByReplacingOccurrencesOfString:

withString:@""];

} // while //

return html;

}

嗯,thank you 。

这个方法用到了,但处理过的字符串只 &nbsp; 未去掉。

最后,用NSString的截取字符串的方法,根据 &nbsp; 截取,然后就解决了