Hi,
Can I right-align a number with leading *spaces*?
F.i. I have the value 2 and I want to display it as " 2".
int num = 2;
string s = num.ToString("0 0"); // gives "02", but I don't want the "0"
s = num.Tostring("# 0"); // gives "2" - no leading space
s = num.ToString(). PadLeft(2); // works, but is a bit cumbersome.
Also, how can I do this in a "format-string"?
s = String.Format(" {0:00}", num); // gives "02"
s = String.Format(" {0:#0}", num); // gives "2"
Hans Kesting
Can I right-align a number with leading *spaces*?
F.i. I have the value 2 and I want to display it as " 2".
int num = 2;
string s = num.ToString("0 0"); // gives "02", but I don't want the "0"
s = num.Tostring("# 0"); // gives "2" - no leading space
s = num.ToString(). PadLeft(2); // works, but is a bit cumbersome.
Also, how can I do this in a "format-string"?
s = String.Format(" {0:00}", num); // gives "02"
s = String.Format(" {0:#0}", num); // gives "2"
Hans Kesting
Comment