.net去除html標簽代碼 

          public  string NoHTML(string Htmlstring)
                  {
                      //刪除腳本
                      Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
                      //刪除HTML
                      Htmlstring = Regex.Replace(Htmlstring, @"<br>", "$br$", RegexOptions.IgnoreCase);
                      Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
                      Htmlstring = Regex.Replace(Htmlstring, @"$br$", "<br>", RegexOptions.IgnoreCase);
                      Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "<br>", 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", "");
                      return Htmlstring;
                  }

          posted on 2009-04-17 12:03 sanmao 閱讀(744) 評論(1)  編輯  收藏

          FeedBack:
          # re: .net去除html標簽代碼[未登錄]
          2014-05-17 09:20 | bobby
          正則表達式在這個程度上己經不夠了,比如清除未知的屬性,和標記,建議使用wuxiu.safehelper  回復  更多評論
            

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


          網站導航:
           

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 阿城市| 泽州县| 南昌县| 河池市| 靖边县| 柞水县| 丹东市| 石河子市| 于田县| 内乡县| 普安县| 新河县| 平阳县| 山阳县| 新野县| 河池市| 武山县| 绥宁县| 丘北县| 雷波县| 江达县| 灵台县| 长海县| 图片| 遵化市| 武邑县| 多伦县| 定州市| 台东市| 叙永县| 安福县| 体育| 巫山县| 东丰县| 饶阳县| 民权县| 达拉特旗| 徐闻县| 济阳县| 汉阴县| 江西省|