asp.net去除HTML标签
2024-09-05 07:23:50
public string NoHTML(string Htmlstring) //替换HTML标记
{
//删除脚本
Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"\[[^\]]+\]", "", RegexOptions.IgnoreCase); //删除HTML
Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<img[^>]*>;", "", RegexOptions.IgnoreCase);
Htmlstring.Replace("<", "");
Htmlstring.Replace(">", "");
Htmlstring.Replace("\r\n", "");
Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
return Htmlstring;
}
最新文章
- Python 【第五章】:线程、进程和协程
- Python socket超时
- coreData数据操作
- python 延迟绑定
- jQuery基础(2)-- jQuery 选择器
- sql 时间查询 /sql中判断更新或者插入/查询一年所有双休日
- 一个基于和围绕Docker生态环境构建的早期项目列表
- 分页sql存储过程算法
- URAL 1097 Square Country 2 离散化
- git log
- linq中的contains条件
- 30个最常用css选择器解析
- C++中构造函数或析构函数定义为private
- Linux重启后raid5的名字发生变化
- sql server 性能调优之 死锁排查
- js 异步代码
- java利用poi解析excel文件
- Python简单介绍
- 机器学习进阶-图像特征harris-角点检测 1.cv2.cornerHarris(进行角点检测)
- .net连mysql数据库汇总
热门文章
- NX二次开发-UFUN创建固定的基准平面UF_MODL_create_fixed_dplane
- 其它课程中的python---4、Matplotlib最最最最简单使用
- ggplot2在一幅图上画两条曲线
- mysql数据库中的索引介绍与优化(转)
- Apache Shiro RememberMe 1.2.4 反序列化漏洞
- <;后端>;Flask框架
- 【2018ACM/ICPC网络赛】徐州赛区
- 006-Java的break和continue
- 一些CSS3新技术
- Windows7 打开word2003提示:向程序发送命令时出现错误 解决方案