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

ASP.NET
动态加载Js代码到Head标签中的脚本
asp.net Parameters.AddWithValue方法在SQL语句的 Where 字句中的用法
ASP.NET 运行时错误: 没有为扩展名“.asax”注册的生成提供程序修正版
Convert.ToInt32与Int32.Parse区别及Int32.TryParse
WebService出现"因 URL 意外地以 结束,请求格式无法识别"的解决方法
asp.net(C#) Xml操作(增删改查)练习
asp.net 分页sql语句(结合aspnetpager)
asp.net开发与web标准的冲突问题的一些常见解决方法
asp.net Repeater中使用if的代码
Asp.net FCKEditor 2.6.3 上传文件没有权限解决方法
C# 命名规则(挺不错的)
asp.net 动态生成控件并获取其值
使用DataGrid中扩展ItemRenderer和HeaderRenderer进行操作
asp.net Hashtable 遍历写法
asp.net GridView和DataList实现鼠标移到行行变色
C# 邮件地址是否合法的验证
.net发送邮件实现代码
ASP.Net 上传图片并生成高清晰缩略图
asp.net 事件与委托分析
C# 无限级分类的实现

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 192 ::
收藏到网摘: 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;
}