我以前必须这样做。所以我将粘贴我在这里使用的代码。
- (NSString *)removeHTMLTags:(NSString *)str
{
NSMutableString *temp_str = [[NSMutableString alloc] initWithString:str];
NSRange openTag = [temp_str rangeOfString:@"<"];
NSRange closeTag = [temp_str rangeOfString:@">"];
while (openTag.length > 0) {
NSRange range;
range.location = openTag.location;
range.length = (closeTag.location - openTag.location) + 1;
[temp_str setString:[temp_str stringByReplacingCharactersInRange:range withString:@""]];
openTag = [temp_str rangeOfString:@"<"];
closeTag = [temp_str rangeOfString:@">"];
}
[temp_str replaceOccurrencesOfString:@"Ä" withString:@"Ä" options:NSLiteralSearch range:NSMakeRange(0, [temp_str length])];
[temp_str replaceOccurrencesOfString:@"Å" withString:@"Å" options:NSLiteralSearch range:NSMakeRange(0, [temp_str length])];
[temp_str replaceOccurrencesOfString:@"Æ" withString:@"Æ" options:NSLiteralSearch range:NSMakeRange(0, [temp_str length])];
while ([temp_str rangeOfString:@" "].location != NSNotFound) {
[temp_str replaceOccurrencesOfString:@" " withString:@" " options:NSLiteralSearch range:NSMakeRange(0, [temp_str length])];
}
while ([temp_str rangeOfString:@" ."].location != NSNotFound) {
[temp_str replaceOccurrencesOfString:@" ." withString:@"." options:NSLiteralSearch range:NSMakeRange(0, [temp_str length])];
}
while ([temp_str rangeOfString:@" ,"].location != NSNotFound) {
[temp_str replaceOccurrencesOfString:@" ," withString:@"," options:NSLiteralSearch range:NSMakeRange(0, [temp_str length])];
}
while ([temp_str rangeOfString:@" ;"].location != NSNotFound) {
[temp_str replaceOccurrencesOfString:@" ;" withString:@";" options:NSLiteralSearch range:NSMakeRange(0, [temp_str length])];
}
return temp_str;
}