zoukankan
html css js c++ java
过滤字符串中带的HTML代码
Code
using
System.Text.RegularExpressions;
/**/
///
<summary>
///
去除HTML标记
///
</summary>
///
<param name="Htmlstring">
包括HTML的源码
</param>
///
<returns>
已经去除后的文字
</returns>
public
static
string
NoHTML(
string
Htmlstring)
{
//
删除脚本
Htmlstring
=
Regex.Replace(Htmlstring,
@"
<script[^>]*?>.*?</script>
"
,
""
, 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.Replace(
"
<
"
,
""
);
Htmlstring.Replace(
"
>
"
,
""
);
Htmlstring.Replace(
"
\r\n
"
,
""
);
Htmlstring
=
HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
return
Htmlstring;
}
一只站在树上的鸟儿,从来不会害怕树枝会断裂,因为它相信的不是树枝,而是它自己的翅膀。与其每天担心未来,不如努力做好现在。
查看全文
相关阅读:
学习mongodb简单安装、连接数据库、增删改查
第三方模块glup学习
npm 借助第三方模块nrm切换淘宝源
nodemon 学习
bootstrap和ie浏览器兼容性问题怎么解决?
所得税
债务重组
非货币性资产交换
政府补助
收入 费用 和利润
原文地址:https://www.cnblogs.com/rhythmK/p/1490693.html
最新文章
app从java到so加密逆向分析过程(一)
得物H5页面url中sign逆向分析
C语言--第0次作业
mysql 数据导出
neo4j
windows系统下pyspark安装
sqluldr用法
对于特征离散化,特征交叉,连续特征离散化非常经典的解释
multi-class、multi-label、multi-output的区别与联系
多标签分类
热门文章
多分类与多标签分类评价指标
tensorflow笔记
解决可ping通但无法访问github网站的问题
设置EditPlus保存时不生成bak文件
lombok链式编程;可以一直点set方法
idea中提交SVN或git时,忽略某些文件,最简单的方式
windows下操作redis的命令
Error running 'PigSellCabinetApplication': Command line is too long. Shorten command line for PigSellCabinetApplication or also for Spring Boot default configuration
Redis设置密码
Express框架学习
Copyright © 2011-2022 走看看