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

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

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


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

          常用鏈接

          留言簿(5)

          隨筆分類(lèi)

          隨筆檔案

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 平度市| 遂溪县| 望江县| 佛学| 秦皇岛市| 凉山| 彭泽县| 苗栗市| 凤台县| 兴宁市| 前郭尔| 玛多县| 泽州县| 南京市| 高唐县| 南部县| 上思县| 阿克| 南岸区| 九寨沟县| 宜都市| 怀宁县| 新竹县| 武胜县| 海安县| 甘德县| 鹰潭市| 克拉玛依市| 娱乐| 威海市| 陵川县| 富平县| 扶绥县| 泊头市| 玛纳斯县| 蕲春县| 措美县| 清涧县| 龙泉市| 瑞安市| 平和县|