zoukankan      html  css  js  c++  java
  • ASP.NET去除字符串中的HTML标记

    public string NoHTML(string Htmlstring) //去除HTML标记
    {
      //删除脚本
      Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
      //删除HTML
      Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
      Htmlstring = Regex.Replace(Htmlstring, @"([
    ])[s]+", "", RegexOptions.IgnoreCase);
      Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
      Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", 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.Replace("<", "");
      Htmlstring.Replace(">", "");
      Htmlstring.Replace("
    ", "");
      Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
    
      return Htmlstring;
    }
  • 相关阅读:
    JS对象、包装类
    js刷题网站
    typeof 返回的数据类型
    一文讲懂什么是函数柯里化,柯里化的目的及其代码实现
    JS 中深拷贝的几种实现方法
    JavaScript 开发的45个经典技巧
    JavaScript中的delete操作符
    IE下iframe不能正常加载,显示空白
    使用Costura.Fody插件将自己写的程序打包成一个可以独立运行的EXE文件
    list获取所有上级
  • 原文地址:https://www.cnblogs.com/ahhswyf/p/3461332.html
Copyright © 2011-2022 走看看