c#过滤html标签

时间:2023-03-09 16:50:21
c#过滤html标签
public string HtmlFilter(string html)
    {
        //设置要删除的标记
        string[] lable = { "font", "span", "strong", " ", "div", "br" ," "};
        foreach (string lb in lable)
        {
            string reg = String.Format(@"</?{0}[^>]*?>", lb);
            //html = Regex.Replace(html, " ", "", RegexOptions.IgnoreCase);         
            html = Regex.Replace(html, reg, "", RegexOptions.IgnoreCase);
        }
        return html;         
        
    } //lable里填写不需要的标签即可。