How to replace string.empty to “0”

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

    You can simply return "0" for null, zero length or whitespace string using this one-liner:

    return String.IsNullOrWhiteSpace(str) ? "0" : str;
    

提交回复
热议问题