当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > asp.net替换和恢复html特殊字符

ASP.NET
DataList绑定到Row[]行集合的问题的方法
充分利用ASP.NET的三种缓存提高站点性能的注意方法
asp.net下文件上传和文件删除的代码
asp.net下日期加减的方法
asp.net动态载入用户控件的方法
asp.net下定制日期输出格式的代码
C#正则用法两例
asp.net图片上传生成缩略图的注意事项
ASP.NET中高质量缩略图的生成代码
DataList 中动态绑定服务器子控件的代码
asp.net下URL网址重写成.html格式、RSS、OPML的知识总结
使用UserControl做网站导航条的思路 分析
ASP.NET中使用AspnetAccessProvider
asp.net下实现URL重写技术的代码
为大家经常为md5加密过的常用admin,admin888,0000密码
利用MS AJAX注册Javascript命名空间并创建类
asp.net(c#)中取得文件物理路径
垃圾代码二三行 ASPX小马
.NET 2.0获取配置文件AppSettings和ConnectionStrings节数据的方法
.NET c# 单体模式(Singleton)

ASP.NET 中的 asp.net替换和恢复html特殊字符


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 148 ::
收藏到网摘: n/a

替换html中的特殊字符需要进行替换的文本。替换完的文本。 /// <summary>
/// 替换html中的特殊字符
/// </summary>
/// <param name="theString">需要进行替换的文本。</param>
/// <returns>替换完的文本。</returns>
public string HtmlEncode(string theString)
{
theString=theString.Replace(">", ">");
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>
/// <param name="theString">需要恢复的文本。</param>
/// <returns>恢复好的文本。</returns>
public string HtmlDiscode(string theString)
{
theString=theString.Replace(">", ">");
theString=theString.Replace("<", "<");
theString=theString.Replace(" "," ");
theString=theString.Replace(" "," ");
theString=theString.Replace(""","\"");
theString=theString.Replace("'","\'");
theString=theString.Replace("<br/> ","\n");
return theString;
}