zoukankan      html  css  js  c++  java
  • .net 去除HTML标签

    public static string GetNoHtmlString(string text)
            {
                if (text == null)
                {
                    text = "";
                }
                //删除脚本
                text = Regex.Replace(text, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
                //删除HTML
                text = Regex.Replace(text, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
                text = Regex.Replace(text, @"([
    ])[s]+", "", RegexOptions.IgnoreCase);
                text = Regex.Replace(text, @"-->", "", RegexOptions.IgnoreCase);
                text = Regex.Replace(text, @"<!--.*", "", RegexOptions.IgnoreCase);
                text = Regex.Replace(text, @"&(quot|#34);", """, RegexOptions.IgnoreCase);
                text = Regex.Replace(text, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
                text = Regex.Replace(text, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
                text = Regex.Replace(text, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
                text = Regex.Replace(text, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
                text = Regex.Replace(text, @"&(iexcl|#161);", "xa1", RegexOptions.IgnoreCase);
                text = Regex.Replace(text, @"&(cent|#162);", "xa2", RegexOptions.IgnoreCase);
                text = Regex.Replace(text, @"&(pound|#163);", "xa3", RegexOptions.IgnoreCase);
                text = Regex.Replace(text, @"&(copy|#169);", "xa9", RegexOptions.IgnoreCase);
                text = Regex.Replace(text, @"&#(d+);", "", RegexOptions.IgnoreCase);
                text.Replace("<", "");
                text.Replace(">", "");
                text.Replace("
    ", "");
                text = HttpContext.Current.Server.HtmlEncode(text).Trim();
                return text;
            }
  • 相关阅读:
    Linux常用快捷键
    如何Oracle 数据库备份与恢复
    Linux常用命令解释
    转摘:商业智能BI的演绎型需求和归纳型需求BI三维框架之内容维研究
    PHP中const的使用
    PHP中define的使用
    Apache配置正向代理与反向代理
    正向代理
    JAVA System.getProperty()参数
    PHP查找当前URL文件扩展名
  • 原文地址:https://www.cnblogs.com/caolingyi/p/8547724.html
Copyright © 2011-2022 走看看