您可以使用 将长字符串拆分为字符串数组componentsSeparatedByString:
。然后对于数组中的每个元素(段落),运行字符串stringByConvertingHTMLToPlainText
以去除剩余的 html 标记。
剥离 html 标记后,您可能希望对内容或段落做更多的工作。
NSString *htmlString = @"<p>first paragraph</p><p>second paragraph</p><p>thrid paragraph</p>";
NSArray *paragraphs = [htmlString componentsSeparatedByString: @"<p>"]; // still includes </p>
for (NSString *singleParagraph in paragraphs) {
// strip out remaining html tags
singleParagraph = [singleParagraph stringByConvertingHTMLToPlainText];
}
// strip out empty or irrelevant indexes and paragraphs you don't need