我正在解析文本并将其存储在NSString变量中。但是当我尝试在屏幕上显示NSString时,我可以在文本中看到html标签,如:<br>
。如何从文本中删除此标记并用空格或其他内容替换它们?
答案 0 :(得分:4)
NSString *str = @"This is<br>a string";
str = [str stringByReplacingOccurrencesOfString:@"<br>" withString:@""];
答案 1 :(得分:0)
-(NSString *) stringByStrippingHTML {
NSRange myRange;
NSString *myString = [[self copy] autorelease];
while ((myRange = [myString rangeOfString:@"<br>" options:NSRegularExpressionSearch]).location != NSNotFound)
myString = [s stringByReplacingCharactersInRange:myRange withString:@""];
return myString;
}