还需要在html和其他特殊字符中解码到空格

时间:2013-12-27 12:56:27

标签: html ios objective-c special-characters decode

如何解码应删除或替换为 等适当字符的html应替换为“”(空格)。

其他特殊角色怎么样?

1 个答案:

答案 0 :(得分:3)

您可以自己创建一个方法,如下所示:

+ (NSString *) replaceHTMLEntitiesInString:(NSString *) htmlString {
    htmlString = [htmlString stringByReplacingOccurrencesOfString:@" " withString:@" "];
    htmlString = [htmlString stringByReplacingOccurrencesOfString:@""" withString:@"\""];
    htmlString = [htmlString stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
    htmlString = [htmlString stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
    return htmlString;
}