用户名:
密 码: 记住
您当前的位置:首页 > 网络编程 > Net教程

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

时间:2015-01-29  来源:互联网  作者:佚名
因此需要以下函数做转换:
复制代码 代码如下:
///<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;
}
来顶一下
返回首页
返回首页
推荐资讯
ASP.NET设计网络硬盘之查看文件夹实现代码 ASP.NET设计网络硬盘之查看文件夹实就像操作本地的计算机一样,需要为每个网络用户提供各自的一
asp.net 网页动态查询条件的实现 asp.net 网页动态查询条件的实现场景 最近有一个需求,会在 mongodb 中插入各种类型的数据,
相关文章
    无相关信息
栏目更新
栏目热门