iphone 开发之过滤html标签
过滤字符串中的html标签的方法:
[cpp]
- (NSString *)filterHtmlTag:(NSString *)originHtmlStr{
NSString *result = nil;
NSRange arrowTagStartRange = [originHtmlStr rangeOfString:@"<"];
if (arrowTagStartRange.location != NSNotFound) { //如果找到
NSRange arrowTagEndRange = [originHtmlStr rangeOfString:@">"];
// NSLog(@"start-> %d end-> %d", arrowTagStartRange.location, arrowTagEndRange.location);
// NSString *arrowSubString = [originHtmlStr substringWithRange:NSMakeRange(arrowTagStartRange.location, arrowTagEndRange.location - arrowTagStartRange.location)];
result = [originHtmlStr stringByReplacingCharactersInRange:NSMakeRange(arrowTagStartRange.location, arrowTagEndRange.location - arrowTagStartRange.location + 1) withString:@""];
// NSLog(@"Result--->%@", result);
return [self filterHtmlTag:result]; //递归,过滤下一个标签
}else{
result = [originHtmlStr stringByReplacingOccurrencesOfString:@" " withString:@""]; // 过滤 等标签
//result = [originHtmlStr stringByReplacingOccurrencesOf ........
}
return result;
}
- (NSString *)filterHtmlTag:(NSString *)originHtmlStr{
NSString *result = nil;
NSRange arrowTagStartRange = [originHtmlStr rangeOfString:@"<"];
if (arrowTagStartRange.location != NSNotFound) { //如果找到
NSRange arrowTagEndRange = [originHtmlStr rangeOfString:@">"];
// NSLog(@"start-> %d end-> %d", arrowTagStartRange.location, arrowTagEndRange.location);
// NSString *arrowSubString = [originHtmlStr substringWithRange:NSMakeRange(arrowTagStartRange.location, arrowTagEndRange.location - arrowTagStartRange.location)];
result = [originHtmlStr stringByReplacingCharactersInRange:NSMakeRange(arrowTagStartRange.location, arrowTagEndRange.location - arrowTagStartRange.location + 1) withString:@""];
// NSLog(@"Result--->%@", result);
return [self filterHtmlTag:result]; //递归,过滤下一个标签
}else{
result = [originHtmlStr stringByReplacingOccurrencesOfString:@" " withString:@""]; // 过滤 等标签
//result = [originHtmlStr stringByReplacingOccurrencesOf ........
}
return result;
}
补充:移动开发 , IOS ,