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;
}
一只站在树上的鸟儿,从来不会害怕树枝会断裂,因为它相信的不是树枝,而是它自己的翅膀。与其每天担心未来,不如努力做好现在。
查看全文
相关阅读:
TCP/IP Checksum 吐槽
RHEL安装时加载第三方raid驱动
RHEL Channel Bonding
关于case语句中声明变量并初始化的注意事项
Allocators与Criterion的相同点及区别
BitSet构造函数的两种特例
Bitset<>用于unordered container时的默认hash函数
C++ Stream
C++Exception知识整理
C++String知识整理
原文地址:https://www.cnblogs.com/rhythmK/p/1490693.html
最新文章
算法设计18—— 最短路径 Bellman-Ford算法
算法设计17—— 最短路径 Dijkstra算法 广度优先搜索
算法设计16——贪婪算法,最小生成树
算法设计15——动态规划,最长公共子序列
pymysql 将数据导入至数据库
python学习——Beautifulsoup 模块
python学习--queue 队列
Python学习----pycharm的快捷方式
nodejs抓取html页面内容
chrome中删除自动同步的网址提示
热门文章
解决php中__FILE__常量只能获取实际路径,不能获取链接路径的问题
php实现socket的服务端和客户端示例
Bottle中文教程:(一)安装
IE6下绑定jquery的mouseover事件,出现抖动现象
wireshark的 rdp dissector
coroutine
getopt vs getopts
nexus 7 2013 驱动安装及root
使用 rpython 在 windows 下生成的程序无法运行
xrdp的rdp前端无法连接Windows 2008的问题
Copyright © 2011-2022 走看看