惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Webroot Blog
Webroot Blog
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
Y
Y Combinator Blog
F
Fortinet All Blogs
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Check Point Blog
博客园 - 【当耐特】
V
V2EX
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
GbyAI
GbyAI
美团技术团队
Jina AI
Jina AI
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
阮一峰的网络日志
阮一峰的网络日志
宝玉的分享
宝玉的分享
人人都是产品经理
人人都是产品经理
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
The GitHub Blog
The GitHub Blog
NISL@THU
NISL@THU
D
Docker
MyScale Blog
MyScale Blog
V
Vulnerabilities – Threatpost
S
SegmentFault 最新的问题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Schneier on Security
K
Kaspersky official blog
AWS News Blog
AWS News Blog
The Hacker News
The Hacker News
Latest news
Latest news
C
CXSECURITY Database RSS Feed - CXSecurity.com
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Know Your Adversary
Know Your Adversary
L
LINUX DO - 热门话题
P
Privacy & Cybersecurity Law Blog
L
Lohrmann on Cybersecurity
C
Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
Cisco Talos Blog
Cisco Talos Blog
N
News and Events Feed by Topic
Google DeepMind News
Google DeepMind News
Help Net Security
Help Net Security
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog

博客园 - refuly

【半原创】将js和css文件装入localStorage加速程序执行 SqlAgent备份脚本 ASP.net 使用HttpHandler实现图片防盗链 水晶头的制作 解决ASP.NET“类型初始值设定项引发异常” 解决vs2005 经WebDeployment发布后 global.asax 事件不启动 C# 实现Epson热敏打印机打印 Pos机用 去掉文件名中的非法字符 - refuly - 博客园 window.onbeforeunload与window.onunlad对比 用Response.Filter生成静态页[要注意并发问题] HttpModule通过修改CSS切换皮肤 asp.net Excel导入&导出 - refuly - 博客园 计算机端口的介绍 Sql Server数据导出EXCEL 获取字符串的真实长度 c# 小数位数处理 新旧身份证合法性验证及验证算法 C#进制转换 Asp.net 备份、还原Ms SQLServer及压缩Access数据库
提取HTML代码中文字的C#函数 - refuly - 博客园
refuly · 2010-07-05 · via 博客园 - refuly
/// <summary>
/// 去除HTML标记
/// </summary>
/// <param name="strHtml">包括HTML的源码 </param>
/// <returns>已经去除后的文字</returns>
public static string StripHTML(string strHtml)
{
    string [] aryReg ={
        @"<script[^>]*?>.*?</script>", 
        @"<(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""])(\\[""tbnr]|[^\7])*?\7|\w+)|.{0})|\s)*?(\/\s*)?>",
        @"([\r\n])[\s]+",
        @"&(quot|#34);",
        @"&(amp|#38);",
        @"&(lt|#60);",
        @"&(gt|#62);", 
        @"&(nbsp|#160);", 
        @"&(iexcl|#161);",
        @"&(cent|#162);",
        @"&(pound|#163);",
        @"&(copy|#169);",
        @"&#(\d+);",
        @"-->",
        @"<!--.*\n"
    };

    string [] aryRep = {
        "",
        "",
        "",
        "\"",
        "&",
        "<",
        ">",
        " ",
        "\xa1",//chr(161),
        "\xa2",//chr(162),
        "\xa3",//chr(163),
        "\xa9",//chr(169),
        "",
        "\r\n",
        ""
    };

    string newReg =aryReg[0];
    string strOutput=strHtml;
    for(int i = 0;i<aryReg.Length;i++)
    {
        Regex regex = new Regex(aryReg[i],RegexOptions.IgnoreCase );
        strOutput = regex.Replace(strOutput,aryRep[i]);
    }

    strOutput.Replace("<","");
    strOutput.Replace(">","");
    strOutput.Replace("\r\n","");

    return strOutput;
}