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;
            }
  • 相关阅读:
    如何避免自己上传的视频或者音频资源被下载
    定期备份服务器上的项目到本地服务器
    查看项目中的laravel的版本
    PHP高并发和大流量的解决方案
    wordpress的安装及使用
    openstack及组件简要介绍
    Java中 如何把Object类型强转成Map<String, String>类型
    JSch基本使用
    Ganymed SSH-2 for Java
    全面解析NIO
  • 原文地址:https://www.cnblogs.com/caolingyi/p/8547724.html
Copyright © 2011-2022 走看看