Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 337
Peter van Kekem Avatar asked Jun 09 '26 13:06

Peter van Kekem


1 Answers

String.Format() supports the ; section separator.

Try e.g. String.Format("{0:#%;;' '}", 0);.

like image 155
Frédéric Hamidi Avatar answered Jun 12 '26 13:06

Frédéric Hamidi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!