Code
1
2
3public string EnCode(string content)
4{
5 string str1=content.Replace("<","<");
6 string str2=str1.Replace(">",">");
7 string str3=str2.Replace("'","'");
8 string str4=str3.Replace(" "," ");
9 string str5=str4.Replace("\r\n","<br>");
10 string str6=str5.Replace("\"",""");
11 string str7=str6.Replace("&","&");
12 return str7;
13}
14
15public string UnCode(string content)
16{
17 string str1=content.Replace("&","&");
18 string str2=str1.Replace(""","\"");
19 string str3=str2.Replace("<br>","\r\n");
20 string str4=str3.Replace(" "," ");
21 string str5=str4.Replace("'","'");
22 string str6=str5.Replace(">",">");
23 string str7=str6.Replace("<","<");
24 return str7;
25}
这是用来做sql 转义字符转换的。刚开始发现只转换了第一个而已。 当时就郁闷了。 用最笨的方法我做两个循环来替换其他的。
后面才发现只要改为: string str1=content.Replace/&/g,"&"); 就可以替换全部了。
public string EnCode(string content)
{
string str1=content.replace(/</g,"<");
string str2=str1.replace(/>/g,">");
}