我是 iphone 开发的菜鸟,我正在尝试将 html 数据转换为字符串格式。目前,我正在使用 stringByConvertingHTMLToPlainText 来完成此操作,但它忽略了 HTML 的格式。我正在转换的 HTML 数据有换行符,但 stringByConvertingHTMLToPlainText 仅删除 HtML 标记并且不格式化结果字符串。任何帮助是极大的赞赏。
我的代码:
NSString *temp = [[[stories objectAtIndex: storyIndex] objectForKey: @"summary"]stringByConvertingHTMLToPlainText];
HTML 数据:
Holiday Inn<br/>Dedham,MA<br/>Sun May 5th 2013-Sun May 5th 2013<br/>Contact: Harry Tong at 603-978-3459<p><sub><i>-- Delivered by <a href="http://feed43.com/">Feed43</a> service</i></sub></p>
结果字符串:
Holiday InnDedham,MASun May 5th 2013-Sun May 5th 2013Contact: Harry Tong at 603-978-3459-- Delivered by "http://feed43.com/"Feed43 service
我需要:
Holiday Inn
Dedham,MA
Sun May 5th 2013-Sun May 5th 2013
Contact: Harry Tong at 603-978-3459
-- Delivered by "http://feed43.com/"Feed43 service
编辑
NSString *html = [[stories objectAtIndex: storyIndex] objectForKey: @"summary"];
NSString *text = [html stringByReplacingOccurrencesOfString:@"<br/>" withString:@" \n "];
NSString *temp = [text stringByConvertingHTMLToPlainText];