zoukankan
html css js c++ java
提取HTML代码中文字的C#函数
/**/
///
<summary>
///
去除HTML标记
///
</summary>
///
<param name="strHtml">
包括HTML的源码
</param>
///
<returns>
已经去除后的文字
</returns>
public
static
string
StripHTML(
string
strHtml)
{
string
[] aryReg
=
{
@"
<script[^>]*?>.*?</script>
"
,
@"
<(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""'])(\\[""'tbnr]|[^\7])*?\7|\w+)|.{0})|\s)*?(\/\s*)?>
"
,
@"
([\r\n])[\s]+
"
,
@"
&(quot|#34);
"
,
@"
&(amp|#38);
"
,
@"
&(lt|#60);
"
,
@"
&(gt|#62);
"
,
@"
&(nbsp|#160);
"
,
@"
&(iexcl|#161);
"
,
@"
&(cent|#162);
"
,
@"
&(pound|#163);
"
,
@"
&(copy|#169);
"
,
@"
&#(\d+);
"
,
@"
-->
"
,
@"
<!--.*\n
"
}
;
string
[] aryRep
=
{
""
,
""
,
""
,
"
\
""
,
"
&
"
,
"
<
"
,
"
>
"
,
"
"
,
"
\xa1
"
,
//
chr(161),
"
\xa2
"
,
//
chr(162),
"
\xa3
"
,
//
chr(163),
"
\xa9
"
,
//
chr(169),
""
,
"
\r\n
"
,
""
}
;
string
newReg
=
aryReg[
0
];
string
strOutput
=
strHtml;
for
(
int
i
=
0
;i
<
aryReg.Length;i
++
)
{
Regex regex
=
new
Regex(aryReg[i],RegexOptions.IgnoreCase );
strOutput
=
regex.Replace(strOutput,aryRep[i]);
}
strOutput.Replace(
"
<
"
,
""
);
strOutput.Replace(
"
>
"
,
""
);
strOutput.Replace(
"
\r\n
"
,
""
);
return
strOutput;
}
青苹果Web应用商店
https://webapp.taobao.com/
PHP/ASP.NET/ASP/UCHOME/DISCUZ! X系列网站开发,详细需求联系
QQ:8511978
查看全文
相关阅读:
如何查看ipynb文件
使用python绘制爱心
使用python将十进制数转为ip地址
python使用下划线分割数字,提高可读性
python的字符串基本操作
pandas为csv添加新的行和列
使用pandas库实现csv行和列的获取
pycharm批量更改变量名
(转)Doxygen文档生成工具
MVC架构学习之Smarty学习——病来而蔫
原文地址:https://www.cnblogs.com/Dicky/p/122372.html
最新文章
比较empty()与 isset()d的区别
每天的自我纠错!
如何将一个文本内容通过PHP 以表格的方式输入到页面上
PHP环境搭建时缺少php7apache2_4.dll怎么办
win7 Host文件修改后无效的解决办法
封装手风琴!使用jQuery!
关于淘宝上星星评价如何做出来的
学习关于display :flex 布局问题!
Android开发之onMeasure(int widthMeasureSpec, int heightMeasureSpec)方法
rtmp搭建直播系统
热门文章
xml 基础属性
全屏显示
动态申请权限的坑
android中getWidth()和getMeasuredWidth()
浮动菜单
补间动画
px dp 互转
添加弹幕
网站是怎么显示出来的(转)
pandas按行按列遍历Dataframe
Copyright © 2011-2022 走看看