欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

去掉html标签方法

程序员文章站 2022-06-21 18:58:38
public static string CleanHtml(string strHtml) { strHtml = Regex.Replace(strHtml, @"(\)|(\)", "", RegexOptions.IgnoreCase | RegexOptions.Singleline); ... ......
        public static string CleanHtml(string strHtml)
        {
            strHtml = Regex.Replace(strHtml, @"(\<script(.+?)\</script\>)|(\<style(.+?)\</style\>)", "", RegexOptions.IgnoreCase | RegexOptions.Singleline);
            //删除标签
            var r = new Regex(@"</?[^>]*>", RegexOptions.IgnoreCase);
            Match m;
            for (m = r.Match(strHtml); m.Success; m = m.NextMatch())
            {
                strHtml = strHtml.Replace(m.Groups[0].ToString(), "");
            }
            return strHtml.Trim();
        }