asp.net替换和恢复html特殊字符
作者:
替换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;
}
/// 替换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;
}
您可能感兴趣的文章:
- ASP.NET对HTML页面元素进行权限控制(一)
- ASP.NET对HTML页面元素进行权限控制(二)
- ASP.NET对HTML页面元素进行权限控制(三)
- Asp.net动态生成html页面的方法分享
- Asp.net 动态加载用户自定义控件,并转换成HTML代码
- asp.net(C#) 动态添加非ASP的标准html控件(如添加Script标签)
- 利用ASP.NET技术动态生成HTML页面
- asp.net 图片验证码的HtmlHelper
- ASP.NET 页面刷新的实现方法(包括html,js)
- asp.net HTML文件上传标签
- asp.net下URL网址重写成.html格式、RSS、OPML的知识总结
- asp.net正则表达式删除指定的HTML标签的代码
- ASP.NET动态增加HTML元素的方法实例小结