![](/img/trans.png)
[英]How to remove tags that are with empty data in html in objective-c?
[英]How to remove tags in html in objective-c?
当Webservice命中时,它在我的文本字段上显示响应,如下所示:响应我在浏览器中命中Web服务时得到的响应。
catid = 38;
created = "May 02 2013";
"created_by" = 588;
fulltext = "<p>
但是,我必须向您解释谴责享乐和赞美痛苦的所有错误观念是如何产生的,我将为您提供一个完整的系统说明,并阐述真相的伟大创造者,人类的总造物主的实际教导。幸福。 没有人会拒绝,厌恶或避免享乐本身,因为它是享乐吗?<\\ p>
<\\ p>
但是,我必须向您解释谴责享乐和赞美痛苦的所有错误观念是如何产生的,我将向您全面介绍该系统,并阐述真相的伟大探索者,人类的建设者的实际教导。幸福。
但是我想用段落更改替换<\\ p> <\\ p>:我想要我的iPhone App上的此响应
catid = 38;
created = "May 02 2013";
"created_by" = 588;
fulltext = "<p>
但是,我必须向您解释谴责享乐和赞美痛苦的所有错误观念是如何产生的,我将为您提供一个完整的系统说明,并阐述真相的伟大创造者,人类的总造物主的实际教导。幸福。 没有人会因为快乐而拒绝,厌恶或避免快乐本身?
但是,我必须向您解释谴责享乐和赞美痛苦的所有错误观念是如何产生的,我将向您全面介绍该系统,并阐述真相的伟大探索者,人类的建设者的实际教导。幸福。
尝试使用此功能删除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:@" "];
html = [html stringByReplacingOccurrencesOfString:[ NSString stringWithFormat:@" "] withString:@" "];
} // while //
return html;
}
不确定</p>
标签为什么总是排在三位,因为有效的HTML应该成对地给标签,例如<p></p>
。 但是,如果您真的确定它总是会出现在三个中,则可以使用NSString实例方法stringByReplacingOccurrencesOfString
:
- (NSString *)replaceThreeParagraphTags:(NSString *)html {
return [html stringByReplacingOccurrencesOfString:@"</p></p></p>" withString:@"\n\n"];
}
基本上,我们只替换每次出现的三个</p>
,并用两个换行符\\n
替换它,因为似乎您想在段落之间插入一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.