menggunakan System.Text.RegularExpressions;//需要引用
// 利用正则表达式去掉"<"和">"之间的内容
string pribadi StripHT(string strHtml)
{
Regex regex=Regex baru("<.+?>",RegexOptions.IgnoreCase);
string strOutput=regex.Ganti(strHtml,"");
kembalikan strOutput;
}
//方法二(不知为什么此方法占用CPU100%)
string statis publik DropHTML(string strHtml)
{
tali [] aryReg ={
@"<skrip[^>]*?>.*?</skrip>",
@"<(/s*)?!?((w+:)?w+)(w+(s*=?s*(([""''])( \["" ''tbnr]|[^7])*?7|w+)|.{0})|s)*?(/s *)?>",
@"([r])[s]+",
@"&(quot|#34);",
@"&(amp|#38);",
@"&(lt|#60);",
@"&(gt|#62);",
@"&(nbsp|#160);",
@"&(iexcl|#161);",
@"&(sen|#162);",
@"&(pon|#163);",
@"&(salin|#169);",
@"&#(d+);",
@"-->",
@"<!--.*"
};
string [] aryRep = {
"",
"",
"",
""",
"&",
"<",
">",
" ",
"xa1",//chr(161),
"xa2",//chr(162),
"xa3",//chr(163),
"xa9",//chr(169),
"",
"R",
""
};
string Reg baru =aryReg[0];
string strKeluaran=strHtml;
for(int i = 0;i<aryReg.Panjang;i++)
{
Regex regex = Regex baru(aryReg[i],RegexOptions.IgnoreCase );
strOutput = regex.Replace(strOutput,aryRep[i]);
}
strOutput.Ganti("<","");
strOutput.Ganti(">","");
strOutput.Ganti("r","");
kembalikan strOutput;
}
http://www.cnblogs.com/wang123/archive/2006/09/16/505758.html