.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 閱讀(741) 評論(1)  編輯  收藏

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

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


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

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 伊宁县| 常熟市| 永修县| 平塘县| 双柏县| 崇左市| 奉化市| 府谷县| 永城市| 犍为县| 岗巴县| 横山县| 河北区| 绥滨县| 海兴县| 房产| 九江县| 泉州市| 五河县| 咸丰县| 北海市| 海阳市| 潜山县| 平湖市| 左云县| 大兴区| 陆丰市| 溧水县| 无极县| 西林县| 商都县| 天水市| 陆丰市| 唐山市| 湘阴县| 永寿县| 友谊县| 仙桃市| 阿坝| 平阳县| 海阳市|