content是根据网址获得的网页源码字符串

- (NSString *)changeToString:(NSString *)content
{
NSRegularExpression *regularExpretion=[NSRegularExpression regularExpressionWithPattern:@"<[^>]*>|\n"
options:0
error:nil]; content = [regularExpretion stringByReplacingMatchesInString:content options:NSMatchingReportProgress range:NSMakeRange(0, content.length) withTemplate:@"-"]; // 替换所有html和换行匹配元素为"-" regularExpretion = [NSRegularExpression regularExpressionWithPattern:@"-{1,}" options:0 error:nil] ;
content = [regularExpretion stringByReplacingMatchesInString:content options:NSMatchingReportProgress range:NSMakeRange(0, content.length) withTemplate:@"-"]; // 把多个"-"匹配为一个"-" // 根据"-"分割到数组
NSArray *arr=[NSArray array];
content = [NSString stringWithString:content];
arr = [content componentsSeparatedByString:@"-"];
NSMutableArray *marr=[NSMutableArray arrayWithArray:arr];
[marr removeObject:@""];
NSMutableString *string = [[NSMutableString alloc] init];
for (int i = 0; i < arr.count; i++) {
[string appendString:[NSString stringWithFormat:@"%@",arr[i]]];
}
return string;
}

iOS中使用正则表达式去掉HTML中的标签元素获得纯文本的方法的更多相关文章

  1. C#用正则表达式去掉Html中的script脚本和html标签

    原文 C#用正则表达式去掉Html中的script脚本和html标签 /// <summary>         /// 用正则表达式去掉Html中的script脚本和html标签     ...

  2. C# 使用正则表达式去掉字符串中的数字,或者去掉字符串中的非数字

            /// 去掉字符串中的数字           public static string RemoveNumber(string key)           {            ...

  3. C# 使用正则表达式去掉字符串中的数字

    /// <summary>/// 去掉字符串中的数字/// </summary>/// <param name="key"></param ...

  4. C# .net 使用正则表达式去掉字符串中的数字

    /// <summary>/// 去掉字符串中的数字/// </summary>/// <param name="key"></param ...

  5. C#中使用 正则表达式 替换img中src路径但保留图片名

    text = Regex.Replace(text, @"(?i)(?<=<img\b[^>]*?src=\s*(['""]?))([^'"& ...

  6. 在Python中使用正则表达式去掉字符串里的html标签

    有时候会获得一些带html标签的字符串,需要把html标签去掉,获得干净的字符串,这时候可以使用正则表达式. 代码如下: import re htmeString = '''<ul id=&qu ...

  7. 【转】C# 使用正则表达式去掉字符串中的数字,或者去掉字符串中的非数字

    源地址:http://www.cnblogs.com/94cool/p/4332957.html

  8. Java中使用正则表达式获取网页中所有图片的路径

    public static List<String> getImageSrc(String htmlCode) { List<String> imageSrcList = ne ...

  9. 过滤eWebeditor等富文本中html标签,获得纯文本信息

    /// <summary> /// 过滤html标签 /// </summary> /// <param name="Htmlstring">& ...

随机推荐

  1. cf E. George and Cards

    http://codeforces.com/contest/387/problem/E 题意:给你n个数,然后在输入k个数,这k个数都在n个数中出现,进行每一次操作就是在n个数中选择长度为w的连续序列 ...

  2. tomcat服务器报Server at localhost was unable to start within 45 seconds的问题

    今天在同一个tomcat服务器下部署了2个不同的应用程序,然后启动时报错:Server at localhost was unable to start within 45 seconds.If th ...

  3. Qt之模型/视图(自定义按钮)(使用QStyleOption的子类进行drawControl,和我用的方法完全不一样)

    http://blog.csdn.net/liang19890820/article/details/50974059

  4. [置顶] export命令-linux

    export 命令 功能说明: 设置或显示环境变量. 语 法: export [-fnp][变量名称]=[变量设置值] 补充说明: 在shell中执行程序时,shell会提供一组环境变量. expor ...

  5. java学习之面向对象概念

    思考的两种方式: 举例: 把大象放到冰箱里 一.面向过程 :[打开冰箱->把大象放里面->关上冰箱门]面向过程注重的是过程,也就是(动作[函数]),然后按照动作依次去执行就好了. 代表语言 ...

  6. Linux下Socket编程的端口问题( Bind error: Address already in use )

    Linux下Socket编程的端口问题( Bind error: Address already in use ) 在进行linux网络编程时,每次修改了源代码并再次编译运行时,常遇到下面的地使用错误 ...

  7. POJ-3693-Maximum repetition substring(后缀数组-重复次数最多的连续重复子串)

    题意: 给出一个串,求重复次数最多的连续重复子串 分析: 比较容易理解的部分就是枚举长度为L,然后看长度为L的字符串最多连续出现几次. 既然长度为L的串重复出现,那么str[0],str[l],str ...

  8. 数据结构(trie,启发式合并):HDU 5841 Alice and Bob

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABJEAAAE6CAIAAAApz1RvAAAgAElEQVR4nO3d3css1b3g8fyTdbHJbD

  9. Contains Duplicate II ——LeetCode

    Given an array of integers and an integer k, find out whether there there are two distinct indices i ...

  10. Windows下动态库的隐式调用

    多年的工作经验告诉我Windows下使用动态库最简单的方法:使用def导出函数,然后隐式调用. 具体做法如下: (1)首先使用visual studio 创建“Win32项目”,如下图: (2)然后在 ...