How to replace string.empty to “0”

后端 未结 10 1759
无人共我
无人共我 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:05

    If you want to check if the value is empty and then set the value to zero, otherwise use the default value you can use an inline if like so:

    return string.IsNullOrWhiteSpace(retString ) ? "0" : retString;
    

提交回复
热议问题