去除字符串中的HTML标签
来源:互联网 发布:阿里云物联网平台 编辑:程序博客网 时间:2024/05/22 00:19
public static string NoHTML(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;
}
{
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;
}
- 去除字符串中的HTML标签
- 去除字符串中的html标签
- 去除字符串中的HTML标签
- 去除字符串中的html标签
- 去除指定字符串中的HTML标签
- C#去除字符串中的html标签
- PHP去除字符串中的html标签
- C#去除指定字符串中的HTML标签
- C#去除指定字符串中的HTML标签相关代码函数
- java去除字符串中的html标签的方法
- java字符串去除html标签
- 猫猫学iOS之去除服务器返回数据中的html标签,去除指定字符串,替换字符串
- AJ学IOS之去除服务器返回数据中的html标签,去除指定字符串,替换字符串
- 去除文本中的HTML标签
- 去除字符串中的Html代码
- 去除字符串中的html标记
- 去除字符串中的html格式
- 使用RegularExpressions去除HTML标签的字符串
- 如何清除访问局域网时保存的密码
- 海量数据处理程序设计技巧(附C++代码)
- qt技巧
- 常用的开源3D游戏引擎(转)
- Linux USB驱动框架分析
- 去除字符串中的HTML标签
- 如何修改主机名
- 浅谈Java中的几种随机数
- 用vim编写C程序的常用命令
- C++编程思想学习-对象的创建与使用
- patch diff stuff
- 如何在Linux下新增加新硬盘
- 写代码犹如写文章
- Microsoft.Practices.EnterpriseLibrary.ConfigConsole.vsix