仅从目标C中的html内容中提取文本

我发现的所有strip函数都是从html内容中提取html元素的。 我正在寻找一个简单的目标c函数给定一个嵌套的文本块,如:

<table border="0" cellpadding="2" cellspacing="7" style="vertical-align:top;"><tr><td width="80" align="center" valign="top"><font style="font-size:85%;font-family:arial,sans-serif"></font></td><td valign="top" class="j"><font style="font-size:85%;font-family:arial,sans-serif"><br /><div style="padding-top:0.8em;"><img alt="" height="1" width="1" /></div><div class="lh"><a href="http://news.google.com/news/url?sa=t&amp;fd=R&amp;usg=AFQjCNFV5azq03nECHSmTV0CI-KwzBFXWA&amp;url=http://www.fool.com/investing/general/2012/03/11/the-justice-department-has-apples-number.aspx"><b>The Justice Department Has ordered <b>Apple</b> .... 

它只会返回司法部门已经下令苹果….

我知道有一个UIWebView Javascriptfunction,但它似乎有点慢,因为它依赖于JavaScript。 我想知道是否有赋予嵌套标签的HTML函数(它会忽略所有的标签和它们的内容,并返回一个普通的内容文本)

谢谢,罗斯

只需使用尖括号拆分string,取其他所有元素,然后将它们连接在一起:

 NSArray *components = [yourString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]; NSMutableArray *componentsToKeep = [NSMutableArray array]; for (int i = 0; i < [components count]; i = i + 2) { [componentsToKeep addObject:[components objectAtIndex:i]]; } NSString *plainText = [componentsToKeep componentsJoinedByString:@""];