去除html标记和替换script标记

2020-12-13 02:34

阅读:592

标签:style   class   code   ext   color   c   

   1:   /// 
   2:          /// 去除HTML标记
   3:          /// 
   4:          /// 包括HTML的源码 
   5:          /// 已经去除后的文字
   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, @"", "", 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, @"


评论


亲,登录后才可以留言!