亲宝软件园·资讯

展开

HTML字符转换 C#中HTML字符转换函数分享

人气:1
想了解C#中HTML字符转换函数讲解的相关内容吗,在本文为您仔细讲解HTML字符转换的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:HTML字符转换,下面大家一起来学习吧。
因此需要以下函数做转换:
复制代码 代码如下:

///<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;
}

加载全部内容

相关教程
猜你喜欢
用户评论