去除html发现的问题以及解决

来源:互联网 发布:淘宝的预约上门取件 编辑:程序博客网 时间:2024/05/04 06:15

网页中去除html标记的需求,但出现了一些奇怪的事

第一种方法

using System.Text.RegularExpressions;

具体的方法:

public static string RemoveStyle(string str)
    {
        var reg = new Regex(@"\s*style\s*=\s*(['|""]).*?\1", RegexOptions.IgnoreCase);
        return reg.Replace(str,"");
    }

 

但远程的虚拟主机一直其实,未加载组件Regular  郁闷

 

技术想了一个解决办法,证明可行

第二种:

 public static string DelHTML(string html)//将HTML去除

{           
 System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"\s*style\s*=\s*(['|""]).*?\1", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        html = regex1.Replace(html, ""); //过滤<script></script>标记
        return html;

    }

 

这个可行,真是奇怪!