Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply string format form left to right

Tags:

string

c#

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?

like image 659
Sankarann Avatar asked Mar 13 '14 11:03

Sankarann


1 Answers

Try this:

var padded = long.Parse((123).ToString().PadRight(8, '0'));
string.Format("{0:00-00-0000}", padded);
like image 107
Jonathas Costa Avatar answered Sep 29 '22 22:09

Jonathas Costa