提取HTML代码中文字的C#函数
来源:互联网 发布:淘宝网 腰带 编辑:程序博客网 时间:2024/04/30 05:09
///提取HTML代码中文字的C#函数
/// <summary>
/// 去除HTML标记
/// </summary>
/// <param name="strHtml">包括HTML的源码 </param>
/// <returns>已经去除后的文字</returns>
using System;
using System.Text.RegularExpressions;
public class StripHTMLTest{
public static void Main(){
string s=StripHTML("<HTML><HEAD><TITLE>中国石龙信息平台</TITLE></HEAD><BODY>faddfs龙信息平台</BODY></HTML>");
Console.WriteLine(s);
}
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;
}
}
- 提取HTML代码中文字的C#函数
- 提取HTML代码中文字的C#函数
- [转]提取HTML代码中文字的C#函数
- 提取HTML代码中文字的C#函数
- 提取HTML代码中文字的C#函数
- 提取HTML代码中文字的C#函数
- 提取HTML代码中文字的C#函数
- 提取HTML代码中文字的C#函数
- 提取HTML代码中文字的C#函数
- 提取HTML代码中文字的C#函数
- 提取HTML代码中文字的C#函数
- 提取HTML代码中文字的C#函数
- 提取HTML代码中文字的C#函数(HTML to TEXT)
- 从HTML代码中提取文字,去掉HTML的标记
- C#提取HTML代码中的文字zt
- C#提取HTML代码中的文字
- C#提取HTML代码中的文字
- C#提取HTML代码中的文字
- 物理地址扩展 (PAE) 和应用程序内存调整
- 启用 XML 安全性
- tc常见错误
- 上传单个文件,这样就可以了
- 忘记写"public"的后果
- 提取HTML代码中文字的C#函数
- XML 安全: 实现安全层,第 1 部分
- 人月神話
- 开发性能良好的数据库
- 用WinXP自带的分区工具,给没有分区的硬盘分区
- minicom的使用
- Hibernate学习笔记(一)
- 头文件的排放要遵守顺序
- 将DataGrid的数据直接导入Excel