Reputation: 2665
How can you make a string that is formatted from a value from left to right?
string.Format("{0:00-00-0000}", 123);
The above returns as 00-00-0123
I would like it to be 12-30-0000
Any idea to achieve this?
Upvotes: 7
Views: 301
Reputation: 1016
Try this:
var padded = long.Parse((123).ToString().PadRight(8, '0'));
string.Format("{0:00-00-0000}", padded);
Upvotes: 5
Reputation: 12797
Another crazy idea is to do some math
int i = 123;
string.Format("{0:00}-{1:00}-{2:0000}", i / 1000000, (i / 10000) % 100, i % 10000);
Upvotes: 0