C#中HTML字符转换函数分享
2018-10-12 13:52
573 查看
因此需要以下函数做转换:
///<summary>
///替换html中的特殊字符
///</summary>
///<paramname="theString">需要进行替换的文本。</param>
///<returns>替换完的文本。</returns>
public static string HtmlEncode(string theString)
{
theString=theString.Replace(">",">");
theString=theString.Replace("<","<");
theString=theString.Replace(" "," ");
theString=theString.Replace("\"",""");
theString = theString.Replace("\'", "'");
theString=theString.Replace("\n","<br/>");
return theString;
}
///<summary>
///恢复html中的特殊字符
///</summary>
///<paramname="theString">需要恢复的文本。</param>
///<returns>恢复好的文本。</returns>
public static string HtmlDiscode(string theString)
{
theString=theString.Replace(">",">");
theString=theString.Replace("<","<");
theString=theString.Replace(" "," ");
theString=theString.Replace(""","\"");
theString = theString.Replace("'", "\'");
theString=theString.Replace("<br/>","\n");
return theString;
}
您可能感兴趣的文章:
相关文章推荐
- C#中HTML字符转换函数分享
- C#中HTML字符转换函数
- C#中HTML字符转换函数
- C# 将html实体编码转换到正常字符 & #40;格式
- c#中文转unicode字符示例分享
- 【转】C# 过滤HTML,脚本,数据库关键字,特殊字符
- c#使用nsoup解析html乱码解决方法分享 nsoup教程
- js replace 全局替换 以表单的方式提交参数 判断是否为ie浏览器 将jquery.qqFace.js表情转换成微信的字符码 手机端省市区联动 新字体引用本地运行可以获得,放到服务器上报404 C#提取html中的汉字 MVC几种找不到资源的解决方式 使用Windows服务定时去执行一个方法的三种方式
- C#判断字符是否为汉字的三种方法分享
- c#判断字符是否为中文的三种方法分享(正则表达式判断)
- C#中可以使用正则表达式来过滤html字符
- 过滤html字符(c#)
- C#从剪贴板获取HTML格式内容含中文字符出现的问题和解决方法
- C# 从剪贴板中读取HTML中的中文字符出现乱码问题的解决方案
- C# 过滤HTML,脚本,数据库关键字,特殊字符
- C#中使用正则表达式来过滤html字符
- c#远程html数据抓取实例分享
- C#中关于从剪贴板中读取HTML格式含中文字符会出现的问题和解决方法
- 在C#中使用正则表达式过滤html字符
- C#使用正则过滤html字符