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;
}
查看全文
相关阅读:
最强神作!Crysis深度剖析与优化指南(1825)
到底什么样的一款游戏就算全3D?
[转贴]因父之名:一个“非科班”的成长史
转载《阅读一款3D引擎的方法备忘》
魔兽世界角色换装
Flash游戏开发之按键控制(复合键,八方向键)
通过MC里的按钮跳转场景
Cuyahoga 的安装
如何从数组中随机取出多个不重复的项
[Flash开发笔记] flash 8 中的 setTimeout()
原文地址:https://www.cnblogs.com/xucanzhao/p/507108.html
最新文章
Codeforces Round #117 (Div. 2) D. Common Divisors
poj(2185) Milking Grid (很好的kmp题目)
hdu (2852) KiKi's KNumber
ZOJ(1649)Rescue
csust 1467: 数学(扩展欧几里得)
Who's in the Middle
IBM Minus One
Best Cow Line
GPA
找零钱
热门文章
今年暑假不AC
Beer Refrigerator
C语言第一章基本概念练习。
【西交OJ】Problem A 扫雷
Problem A 人品
Skeletal Animation(骨骼动画)
年度巅峰对决 GOW携虚幻3决战Crysis
3dsmax插件开发新手上路
最强神作!Crysis深度剖析与优化指南(2631)
[Visual C++]error C2220: 警告被视为错误
Copyright © 2011-2022 走看看