提取HTML代碼中文字的C#函數(shù)
/// <summary>
/// 去除HTML標(biāo)記
/// </summary>
/// <param name="strHtml">包括HTML的源碼 </param>
/// <returns>已經(jīng)去除后的文字</returns>
public static string StripHTML(string strHtml)
{
string [] aryReg ={
@"<script[^>]*?>.*?</script>",
@"<(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""'])(\\[""'tbnr]|[^\7])*?\7|\w+)|.{0})|\s)*?(\/\s*)?>",
@"([\r\n])[\s]+",
@"&(quot|#34);",
@"&(amp|#38);",
@"&(lt|#60);",
@"&(gt|#62);",
@"&(nbsp|#160);",
@"&(iexcl|#161);",
@"&(cent|#162);",
@"&(pound|#163);",
@"&(copy|#169);",
@"&#(\d+);",
@"-->",
@"<!--.*\n"
};
string [] aryRep = {
"",
"",
"",
"\"",
"&",
"<",
">",
" ",
"\xa1",//chr(161),
"\xa2",//chr(162),
"\xa3",//chr(163),
"\xa9",//chr(169),
"",
"\r\n",
""
};
string newReg =aryReg[0];
string strOutput=strHtml;
for(int i = 0;i<aryReg.Length;i++)
{
Regex regex = new Regex(aryReg[i],RegexOptions.IgnoreCase );
strOutput = regex.Replace(strOutput,aryRep[i]);
}
strOutput.Replace("<","");
strOutput.Replace(">","");
strOutput.Replace("\r\n","");
return strOutput;
}
相關(guān)文章
Web.config 和 App.config 的區(qū)別分析
Web.config 和 App.config 的區(qū)別分析,需要的朋友可以參考一下2013-05-05在.NET中使用Newtonsoft.Json轉(zhuǎn)換,讀取,寫入的方法介紹
Newtonsoft.Json.JsonConvert類是非微軟提供的一個(gè)JSON序列化和反序列的開源免費(fèi)的類庫(kù)2012-08-08.Net學(xué)習(xí)筆記之Layui多圖片上傳功能
這篇文章主要給大家介紹了關(guān)于.Net學(xué)習(xí)筆記之Layui多圖片上傳功能的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用.Net具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07ASP.NET中Session和Cache的區(qū)別總結(jié)
這篇文章主要介紹了ASP.NET中Session和Cache的區(qū)別總結(jié),本文結(jié)合使用經(jīng)驗(yàn),總結(jié)出了5點(diǎn)Session緩存和Cache緩存的區(qū)別,需要的朋友可以參考下2015-06-06.net 操作xml的簡(jiǎn)單方法及說(shuō)明
.net 操作xml的簡(jiǎn)單方法及說(shuō)明,需要的朋友可以參考一下2013-06-06ASP.net中保持頁(yè)面中滾動(dòng)條狀態(tài)的代碼
在ASP.Net頁(yè)面中,每次回發(fā)都會(huì)造成頁(yè)面回到頂部,那么怎樣讓它保持刷新頁(yè)面前的位置上,使得頁(yè)面提交后還在原來(lái)的位位置。2011-06-06