.net去除html標(biāo)簽代碼 

          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) 評(píng)論(1)  編輯  收藏

          FeedBack:
          # re: .net去除html標(biāo)簽代碼[未登錄](méi)
          2014-05-17 09:20 | bobby
          正則表達(dá)式在這個(gè)程度上己經(jīng)不夠了,比如清除未知的屬性,和標(biāo)記,建議使用wuxiu.safehelper  回復(fù)  更多評(píng)論
            

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


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

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 黄山市| 夏邑县| 防城港市| 石河子市| 顺昌县| 新余市| 同德县| 武鸣县| 大城县| 吉木乃县| 迭部县| 合肥市| 河源市| 永年县| 林口县| 兰溪市| 定南县| 无棣县| 太仓市| 四平市| 维西| 搜索| 麦盖提县| 永登县| 喀喇沁旗| 苍山县| 东阳市| 温宿县| 黔江区| 三门县| 沁源县| 湖北省| 绥江县| 林口县| 墨脱县| 海原县| 南召县| 万山特区| 屏东县| 宁武县| 兴化市|