using System.Text.RegularExpressions;//需要引用
//利用正则表达式除去"<"和">"之间的内容
私有字符串 StripHT(字符串 strHtml)
{
正则表达式 regex=new Regex("<.+?>",RegexOptions.IgnoreCase);
字符串 strOutput=regex.Replace(strHtml,"");
返回 str 输出;
}
//方法二(不知道为什么这个方法占用CPU100%)
public static string DropHTML(string strHtml)
{
字符串[] aryReg ={
@"<脚本[^>]*?>.*?</脚本>",
@"<(/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);”,
@"&(cent|#162);",
@“&(磅|#163);”,
@“&(复制|#169);”,
@"&#(d+);",
@“-->”,
@"<!--.*"
};
字符串[] aryRep = {
"",
"",
"",
""",
“&”,
“<”,
”>”,
“”,
"xa1",//chr(161),
"xa2",//chr(162),
"xa3",//chr(163),
"xa9",//chr(169),
"",
“r”,
””
};
字符串 newReg =aryReg[0];
字符串 strOutput=strHtml;
for(int i = 0;i<aryReg.Length;i++)
{
正则表达式 正则表达式 = new Regex(aryReg[i],RegexOptions.IgnoreCase );
strOutput = regex.Replace(strOutput,aryRep[i]);
strOutput.Replace
("<","");
strOutput.Replace(">","");
strOutput.Replace("r","");
返回 str 输出;
}
http://www.cnblogs.com/wang123/archive/2006/09/16/505758.html