提取html代码中文字的c#函数_c#应用

2008-02-23 05:44:47来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

/// <summary>
/// 去除HTML标记
/// </summary>
/// <param name="strHtml">包括HTML的源码 </param>
/// <returns>已去除后的文字</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;
}


标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇: c#中使用sendmessage_c#应用

下一篇: hfc反向通道的调整(上)_视频通信