1:   /// <summary>
   2:          /// 去除HTML标记
   3:          /// </summary>
   4:          /// <param name="NoHTML">包括HTML的源码 </param>
   5:          /// <returns>已经去除后的文字</returns>
   6:          public static string RemoveHTML(string Htmlstring)
   7:          {
   8:              if (string.IsNullOrEmpty(Htmlstring))
   9:              {
  10:                  return string.Empty;
  11:              }
  12:              //删除脚本
  13:              Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
  14:   
  15:              //删除HTML
  16:              Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
  17:              Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
  18:              Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
  19:              Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
  20:              Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
  21:              Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
  22:              Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
  23:              Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
  24:              Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
  25:              Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
  26:              Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
  27:              Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
  28:              Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
  29:              Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
  30:              Htmlstring.Replace("<", "");
  31:              Htmlstring.Replace(">", "");
  32:              Htmlstring.Replace("\r\n", "");
  33:   
  34:              return Htmlstring;
  35:          }
  36:   
  37:   
  38:          #region 正则表达式替换包含script脚本攻击的script代码
  39:          /// <summary>
  40:          /// 正则表达式替换包含script脚本攻击的script代码
  41:          /// author:Andrew.He
  42:          /// </summary>
  43:          /// <param name="scriptString">包含脚本攻击的字符串</param>
  44:          /// <returns>替换脚本攻击的字符串</returns>
  45:          public static string RemoveScript(string scriptString)
  46:          {
  47:              if (string.IsNullOrEmpty(scriptString))
  48:              {
  49:                  return scriptString;
  50:              }
  51:   
  52:              //执行替换操作
  53:              scriptString = Regex.Replace(scriptString, @"<[ ]*script", "[script ", RegexOptions.IgnoreCase);
  54:              scriptString = Regex.Replace(scriptString, @"/[ ]*script[ ]*>", " /script]", RegexOptions.IgnoreCase);
  55:   
  56:              return scriptString;
  57:          }
  58:          #endregion

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

最新文章

  1. OpenCASCADE Job - dimue
  2. 【原】iOS学习之Quartz2D(1)
  3. Spark的持久化简记
  4. sqlite之WAL模式
  5. Go 语言学习
  6. Struts2通配符问题(待解决)
  7. Python urllib模块urlopen()与urlretrieve()详解
  8. A Tour of Go Methods continued
  9. Java Nio 笔记
  10. java --jfree报表
  11. JavaScript实现轮播图效果
  12. php三级联动(html,php两个页面)
  13. 免费ARP
  14. rabbitmq 消息的状态转换
  15. lua的table的删除操作
  16. bzoj 2081 [Poi2010]Beads hash+调和级数
  17. 有趣的IntegerCache
  18. 在a标签的href用户#name 的可以实现页面 上下跳转
  19. Codeforces Round #380 (Div. 2)/729E Subordinates 贪心
  20. [k8s]k8s-web-terminal配置使用 &amp; etcdui etcd browser配置 &amp; etcdkeeper3配置

热门文章

  1. leetcode算法: Find the Difference
  2. 云+社区技术沙龙:Kafka meetup 深圳站报名开启
  3. 错误解决:HibernateSystemException-HHH000142: Javassist Enhancement failed
  4. POJ-3617 Best Cow Line---字符串贪心
  5. JavaScript中内存使用规则--堆和栈
  6. hue集成hive访问报database is locked
  7. spring 依赖注入时,什么时候会创建代理类
  8. 一文了解安卓APP逆向分析与保护机制
  9. bzoj1272 Gate Of Babylon
  10. [AHOI2012]铁盘整理