C#  去所有 html標(biāo)簽的代碼|去除html標(biāo)簽代碼   

           public string NoHTML(string Htmlstring) //去除HTML標(biāo)記
              {
                  //刪除腳本
                  Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
                  //刪除HTML
                  Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
                  Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
                  Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
                  Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);

                  Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
                  Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
                  Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
                  Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
                  Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
                  Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
                  Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
                  Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
                  Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
                  Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);

                  Htmlstring.Replace("<", "");
                  Htmlstring.Replace(">", "");
                  Htmlstring.Replace("\r\n", "");
                  Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();

                  return Htmlstring;
              }

          posted on 2010-07-23 15:12 sanmao 閱讀(2729) 評論(2)  編輯  收藏

          FeedBack:
          # re: C# 去所有 html標(biāo)簽的代碼|去除html標(biāo)簽代碼
          2011-08-06 13:36 | ss
          不行啊
            回復(fù)  更多評論
            
          # re: C# 去所有 html標(biāo)簽的代碼|去除html標(biāo)簽代碼[未登錄]
          2011-12-29 15:51 | paul
          試過了,可以用,tks  回復(fù)  更多評論
            

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 和龙市| 株洲县| 稷山县| 固原市| 海盐县| 乌兰县| 微山县| 德兴市| 凤凰县| 康乐县| 阿巴嘎旗| 文昌市| 彝良县| 曲周县| 盐山县| 嘉义市| 恭城| 香格里拉县| 象山县| 利辛县| 达拉特旗| 赤峰市| 普兰店市| 图木舒克市| 时尚| 洛浦县| 望谟县| 瑞金市| 昔阳县| 湘潭市| 女性| 凌海市| 阿坝县| 德清县| 竹溪县| 简阳市| 临汾市| 灌南县| 平邑县| 台山市| 南充市|