How to replace string.empty to “0”

后端 未结 10 1782
无人共我
无人共我 2021-01-27 11:15

Just like the title says.

I\'ve tried doing str.Replace(\"\",\"0\"); but it gave me error because oldValue has zero length.

Is it possi

10条回答
  •  暖寄归人
    2021-01-27 12:01

    It is not possible to replace string.Empty by "0". It will throw ArgumentException.

        An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll.
    Additional information: String cannot be of zero length.
    

    You can try following code:

    if(retString == string.Empty)
    {
    retString = "0";
    }
    

提交回复
热议问题