0

我正在解析文本并将其存储在 NSString 变量中。但是,当我尝试在屏幕上显示 NSString 时,我可以在文本中看到 html 标签,例如:<br>。如何从我的文本中删除此标签并将其替换为空格或其他内容?

4

2 回答 2

4
NSString *str = @"This is<br>a string";

str = [str stringByReplacingOccurrencesOfString:@"<br>" withString:@""];
于 2012-06-04T10:16:08.513 回答
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; 
}
于 2012-06-04T10:13:25.450 回答