国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > web前端 > jscript > JavaScript 的 replace 函数

JavaScript 的 replace 函数

来源:程序员人生   发布时间:2013-12-05 12:00:55 阅读次数:2809次
public string EnCode(string content)
{
string str1=content.Replace("<","<");
string str2=str1.Replace(">",">");
string str3=str2.Replace("'","&apos;");
string str4=str3.Replace(" "," ");
string str5=str4.Replace("","<br>");
string str6=str5.Replace(""",""");
string str7=str6.Replace("&","&");
return str7;
}

public string UnCode(string content)
{
string str1=content.Replace("&","&");
string str2=str1.Replace(""",""");
string str3=str2.Replace("<br>","");
string str4=str3.Replace(" "," ");
string str5=str4.Replace("'","&apos;");
string str6=str5.Replace(">",">");
string str7=str6.Replace("<","<");
return str7;

 这是用来做sql 转义字符转换的。刚开始发现只转换了第一个而已。 当时就郁闷了。 用最笨的方法我做两个循环来替换其他的。后面才发现只要改为: string str1=content.Replace/&amp;/g,"&"); 就可以替换全部了。

public string EnCode(string content)
{
string str1=content.replace(/</g,"<");
string str2=str1.replace(/>/g,">");
}
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
为码而活
积分:4237
15粉丝
7关注
栏目热点
关闭
程序员人生