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
查看全文
相关阅读:
poj2774
GDOI2012 字符串
poj3261
poj1743
bzoj 2565 manacher
归档-ios
学习
ViewPager动态加载、删除页面
android:ScrollView嵌套ListView的问题
Android学习笔记进阶之在图片上涂鸦(能清屏)
原文地址:https://www.cnblogs.com/Dicky/p/122372.html
最新文章
Python--模块
Python--集合
Python--函数
Python--文件修改
python--文件读写
Python--文件操作
bzoj 1593: [Usaco2008 Feb]Hotel 旅馆
codves 4919 线段树练习4
3304 水果姐逛水果街Ⅰ
codves 4927 线段树练习5
热门文章
stl 优先队列(堆)
noip 关押罪犯 (并查集)
动态规划 树型DP
LCA(树上倍增 || rmq&lca||)
搜索场 day1 A 求和
NOI2014 随机数生成器.
bzoj 2002
GDKOI2014 基因模式
GDOI2013 哈希和
bzoj2754
Copyright © 2011-2022 走看看