zoukankan      html  css  js  c++  java
  • 从HTML代码中提取文字,去掉HTML的标记

    public static string NoHTML(string Htmlstring)
        {
            //删除脚本
            Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
            //删除HTML
            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, @"<!--.*", "", 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("\r\n", "");
            Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();

            return Htmlstring;
        }

    using System.Text.RegularExpressions;//需要引用

      // 利用正则表达式去掉"<"和">"之间的内容
      private string StripHT(string strHtml)
      {
       Regex regex=new Regex("<.+?>",RegexOptions.IgnoreCase);
       string strOutput=regex.Replace(strHtml,"");
       return strOutput;
      }

  • 相关阅读:
    华为交换机批量创建VLAN;端口组配置命令
    不同VLAN下实现网络互相通信(配置ip static静态路由进行数据转发)
    不同VLAN下实现网络互相通信(配置port trunk pvid vlan进行数据转发)
    不同VLAN下实现网络互相通信(配置Vlanif IP进行数据转发)
    Lambda表达式
    mysql安装
    多线程 聊天程序
    程序实现 传输图片
    网络编程 编程聊天小程序
    水印
  • 原文地址:https://www.cnblogs.com/Hdsome/p/1379266.html
Copyright © 2011-2022 走看看