替换双连续单引号

时间:2015-08-28 20:52:54

标签: c# string replace special-characters single-quotes

我试图将双连续的单引号替换为null,如下所示:

//my string is " replace '' to null "
str.Replace("''", "null");
//now my string is " replace null to null "

但这种情况正在发生:

//my string is " replace '' to null "
str.Replace("''", "null");
//sadly my string still is " replace '' to null "

任何提示?

1 个答案:

答案 0 :(得分:2)

string.Replace不会修改输入string - 而是返回新的输入str = str.Replace("''", "null"); 。将其重新分配给您的变量以查看更改。

$ docker restart db
db
$ docker run -t -i --rm --link db:db training/webapp /bin/bash
root@aed84ee21bde:/opt/webapp# cat /etc/hosts
172.17.0.7  aed84ee21bde
. . .
172.17.0.9  db