使用kindeditor作为文本编辑器,当我在word里面复制文本过来的时候会报错。
因为Access数据库是不允许存储有特殊字符“&”或HTML代码的?解决方法就是在存入数据库之前,对字符进行替换编码,提取时对字符进行替换解码。
在asp.net里面非常简单!微软为你做了编码和解码方法。代码如下。
/// <summary>
/// 插入SQL时替换字符
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string Encode(string str)
{
str= System.Web.HttpUtility.HtmlEncode(str);
return str;
}
/// <summary>
/// 取SQL值时还原字符
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string Decode(string str)
{
str = System.Web.HttpUtility.HtmlDecode(str);
return str;
}
也可以直接用
HttpUtility.HtmlEncode(str); HttpUtility.HtmlDecode(str)
编码和解码。比起自己替换字符方便很多,还不用担心会错,毕竟是微软官方做的。