zoukankan      html  css  js  c++  java
  • C#去除HTML标签方法

    public static string ExecRepaceHTML(string Htmlstring) 

    Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>""", RegexOptions.IgnoreCase); 
    Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>""", RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+""", RegexOptions.IgnoreCase); 
    Htmlstring = Regex.Replace(Htmlstring, @"-->""", RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring, @"<!--.*\n""", RegexOptions.IgnoreCase); 
    Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);""\"", RegexOptions.IgnoreCase); 
    Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);""&", RegexOptions.IgnoreCase); 
    Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);""<", RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);"">", RegexOptions.IgnoreCase); 
    Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);"" ", RegexOptions.IgnoreCase); 
    Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);""\xa1", RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);""\xa2", RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);""\xa3", RegexOptions.IgnoreCase);
    Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);""\xa9", RegexOptions.IgnoreCase); 
    Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);""", RegexOptions.IgnoreCase); 
    Htmlstring = Regex.Replace(Htmlstring, @"\s"""); Htmlstring.Replace("<"""); Htmlstring.Replace(">""");
    Htmlstring.Replace("\r\n"""); 
    Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
    return Htmlstring;
    }
  • 相关阅读:
    HashMap源码解读(转)
    使用javascript开发2048
    程序猿接私活经验总结,来自csdn论坛语录
    Cocos2d-x实例:设置背景音乐与音效- AppDelegate实现
    Jenkins(二)
    SVN高速新手教程
    Visio Premium 2010密钥+破解激活方法
    oracle中LAG()和LEAD()等分析统计函数的使用方法(统计月增长率)
    shell语法简单介绍
    memset函数具体说明
  • 原文地址:https://www.cnblogs.com/TSPWater/p/2206814.html
Copyright © 2011-2022 走看看