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. JavaScript Maintainable

    1. Avoid conflict with Native Variable namespace

  2. 这个知识点不错,,学习一下先。。。无状态服务(stateless service)(转)

    这样的应用,显得高级一些哟~~:) +================== http://kyfxbl.iteye.com/blog/1831869 ========================= ...

  3. Ganglia监控搭建

    一.Ganglia介绍: Ganglia是一个监控服务器.集群的开源软件,能够用曲线图表现最近一个小时,最近一天,最近一周,最近一月,最近一年的服务器或者集群的cpu负载,内存,网络,硬盘等指标.Ga ...

  4. 图论(KM算法):COGS 290. [CTSC2008] 丘比特的烦恼

    290. [CTSC2008] 丘比特的烦恼 ★★★   输入文件:cupid.in   输出文件:cupid.out   简单对比 时间限制:1 s   内存限制:128 MB 随着社会的不断发展, ...

  5. 斜率优化(CDQ分治,Splay平衡树):BZOJ 1492: [NOI2007]货币兑换Cash

    Description Input 第一行两个正整数N.S,分别表示小Y 能预知的天数以及初始时拥有的钱数. 接下来N 行,第K 行三个实数AK.BK.RateK,意义如题目中所述 Output 只有 ...

  6. Implement Stack using Queues ——LeetCode

    Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...

  7. WCF扩展系列 - 行为扩展(Behaviors)

    原文地址:http://www.cnblogs.com/Creator/archive/2011/05/21/2052687.html 这个系列的第一部分将会重点关注WCF行为(behaviors), ...

  8. 《A First Course in Probability》-chaper4-离散型随机变量-随机变量函数的期望

    给定一个离散型随机变量X,根据定义我们容易得到期望E[X],但是在具体的问题当中,我们会得到一个关于X的另一个函数关系Y=g(X),那么我们就非常的好奇,根据函数关系Y=g(X)和随机变量X的分布列数 ...

  9. POJ 1456 Supermarket

    题意:商场卖东西,每种商品有两个属性,一种是价格pi,另一种是保质期di,每种商品只能在天数<=di的时候卖出.每天只能卖一种商品,问最多能卖出价格之和为多少的商品.(n <= 10^4, ...

  10. 常用的Linux操作一

    Linux 常用的操作必须明白. 1.ls  和ll 列出文件的目录. 2.tail -f XXX  查看文件. 3.chmod -R 777 XXX.jar 赋予权限 4.cat 查看文件 -n 对 ...