-2

我正在尝试将双连续的单引号替换为空,如下所示:

//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 "

有小费吗?

4

1 回答 1

2

string.Replace不修改输入string,而是返回一个新的。将其重新分配回您的变量以查看更改。

str = str.Replace("''", "null");
于 2015-08-28T20:54:52.770 回答