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应用开发之十一:常用的三种动画表现效果
- Android:实现TabWidget选项卡按钮在屏幕下方
- Memory on the iPhone
- iPhone开发学习笔记006—— NSNotification自定义通知名
- ios学习笔记(二)xcode 4.3.2下实现基本交互
- Lexical or Preprocessor Issue 'xxx.h
- (iPhone/iPad开发)presentViewController相应方法在SDK5.0前后
- 多线程之NSInvocationOperation
- ios开发问题:添加库和复制其它工程文件编译错误问题
- iphone开发之object c基础一定义接口