Pad left with zeroes

Microsoft has built in functions for this:

someString = someString.PadLeft(8, '0');

And here’s an article on MSDN

To use a regular expression, do something like this:

string someText = "asd 123 rete"; 
someText = Regex.Replace(someText, @"\d+", n => n.Value.PadLeft(8, '0'));

Leave a Comment