zoukankan
html css js c++ java
用正则彻底去除HTML\CSS\script代码
/**/
///
<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;
}
查看全文
相关阅读:
MD5双重加密设计
ComBox(自定义封装)LimitToList属性和做到移走光标不是下拉项清空输入
强制下线功能
广播
动态添加碎片
RecyclerView
Listview的运行效率
Listview
通知栏
补间动画
原文地址:https://www.cnblogs.com/xucanzhao/p/507108.html
最新文章
iOS面试题常见问题搜罗 ♪(^∇^*)
当WebView加载的是非HTML网页内容时,如何获取它的内容?
最简单粗暴的方式实现无限循环滚动的UIScrollView
为PNG,JEPG瘦身,比TinyPNG好用的ImageAlpha,Free免费哟
解决UIScrollView中添加子控件出现“UIScrollView Scrollable Content Size Ambiguity”的办法
A crash course on CoreGraphics(CoreGraphics的基本介绍)
原子类-AtomicIntegerFieldUpdater
原子类-Atomic*Array
原子类-AtomicInteger
原子类-概述
热门文章
自旋锁和阻塞锁
锁的升降级
读写锁的策略
公平锁与非公平锁
Lock锁-Lock接口
Lock锁-概述
mapreduce 二次排序
DGV封装禁止列排序
集合根据属性分组获得多个集合进行操作
TabControl动态显示Form窗体
Copyright © 2011-2022 走看看