當我們從後台獲取一個帶有H5標簽的字符串的時候,我們將其正常顯示了,但是如果字符串過長我們要求進行根據字符串的進行自定義控件的高度,因此我們要將字符串中的H5標簽去除之後再計算字符的高度:
NSString *tagString = @"字符串";
NSScanner * scanner = [NSScanner scannerWithString:tagString];
NSString * text = nil;
while([scanner isAtEnd]==NO)
{
//找到標簽的起始位置
[scanner scanUpToString:@"<" intoString:nil];
//找到標簽的結束位置
[scanner scanUpToString:@">" intoString:&text];
//替換字符
tagString = [tagString stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@>",text] withString:@""];
}
//去掉特殊字符
NSCharacterSet *setString = [NSCharacterSet characterSetWithCharactersInString:@"@/:;()¥「」"、[]{}#%-*+=_\\|~<>$?^?'@#$%^&*()_+'\""];
NSString *disposeString = [[NSString stringWithFormat:@"%@",@"字符串"] stringByTrimmingCharactersInSet:setString];