Suppose I have string like this ".1.12.3.4.12.4."
As a result I would like to get ".01.12.03.04.12.04."
As you can see, I want all numbers of length == 1 to become of length == 2 with zero at the beginning. How can I achieve this?
Try this:
var input = ".1.12.3.4.12.4.";
var output = Regex.Replace(input, @"\.(\d)(?=\.)", ".0$1");
Console.WriteLine(output); // .01.12.03.04.12.04.
1.2.4 i.e 1 at the beginningSplit the string into tokens, format each resulting number and then join them back:
var input = ".1.12.3.4.12.4.";
var output = string.Join(
    ".", 
    input.Split('.')
         .Select(i => i.Length == 0 ? "" : i.PadLeft(2, '0'))
);
The best part of this solution is that you can easily change the length of the padded result.