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];    //递归,过滤下一个标签
	
相关新闻>>
- 发表评论
- 
				
- 最新评论 进入详细评论页>>









![[iPhone中级]iPhone团购信息客户端的开发 (二)](/uploads/allimg/131022/200H11235-0-lp.png)
