/// <summary>
/// 替换字符串中的特殊字符,
/// flag = true:替换串中的大于和小于号等特殊字符为转义标记
/// flag = false:将经过转义的串,转为正常输出
/// </summary>
/// <param name="strContent"></param>
/// <param name="flag"></param>
/// <returns></returns>
public static string ReplaceStr(string strContent,bool flag)
{
if (flag)
{
strContent=strContent.Replace("&","&");
strContent=strContent.Replace("'","''");
strContent=strContent.Replace("<","<");
strContent=strContent.Replace(">",">");
strContent=strContent.Replace("\"",""");
strContent=strContent.Replace("\r\n","<br/>");
//strContent=strContent.Replace(" "," ");
return strContent;
}
else
{
strContent=strContent.Replace("&","&");
strContent=strContent.Replace("''","'");
strContent=strContent.Replace("<","<");
strContent=strContent.Replace(">",">");
strContent=strContent.Replace(""","\"");
strContent=strContent.Replace("<br/>","\r\n");
//strContent=strContent.Replace(" "," ");
return strContent;
}
}
/// 替换字符串中的特殊字符,
/// flag = true:替换串中的大于和小于号等特殊字符为转义标记
/// flag = false:将经过转义的串,转为正常输出
/// </summary>
/// <param name="strContent"></param>
/// <param name="flag"></param>
/// <returns></returns>
public static string ReplaceStr(string strContent,bool flag)
{
if (flag)
{
strContent=strContent.Replace("&","&");
strContent=strContent.Replace("'","''");
strContent=strContent.Replace("<","<");
strContent=strContent.Replace(">",">");
strContent=strContent.Replace("\"",""");
strContent=strContent.Replace("\r\n","<br/>");
//strContent=strContent.Replace(" "," ");
return strContent;
}
else
{
strContent=strContent.Replace("&","&");
strContent=strContent.Replace("''","'");
strContent=strContent.Replace("<","<");
strContent=strContent.Replace(">",">");
strContent=strContent.Replace(""","\"");
strContent=strContent.Replace("<br/>","\r\n");
//strContent=strContent.Replace(" "," ");
return strContent;
}
}
解决方案 »
- 用户名保存期限
- 被人直接注入了,怎么解决,代码
- 怎么在RowCommand里 获得GridView里某一字段的值
- asp.net中怎么去实现网上付费
- 在JS中怎样获得客户端控件
- 页面加载用户控件的问题
- 求助!multiview的问题在线等!
- 为何错了? Onclick="javascript:return confirm(您真的要归还分类号为的成果报" + <%# DataBinder.Eval(Container.DataItem, "分类号").T
- 我的网站发布了,大家多来支持啊!
- 请教个GridView显示数据库内容的问题
- 数据库存储多类型文件WEB显示问题。困扰多日,大侠们帮忙!
- 关于打开ASP.NET的错误问题,请大家帮忙解决
show的时候用Server.HtmlEncode就可以了
To: cpp2017(幕白兄)
我直接在页面中输入保存会出错(如带'的文本),是否在页面中要导入什么东东?
能否给个具体的实例:
保存时,显示时,修改时就要点提示一下。
function check(str)
{
var pattern=/^([\u4e00-\u9fa5]|[0-9_a-zA-Z]){1,20}$/;
if(!pattern.test(str))
{
alert('只能输入中文,字母或者数字!');
}
}
</script>