Search code examples
c#zerostring.format

string.Format() Blank Zero


In my application, there are possibilities to format a string using the string.Format() function. I want to add the possibility to return blank when the result is zero.

As far as I can see, it is possible to do this using the code: 0.toString("0;; ");, but as i already mentioned, I need to use the string.Format() function (since it must be able to use for example the {0:P} format for percentage.

Does anyone knows how to blank a zero value using the string.Format() function?


Solution

  • why don't you do it with if else statement?

    string result = String.Format(the value);
    if(result=="0")
    {
       result=" ";
    }