Left Zeros [duplicate]

2

I will receive several numbers that can be up to 9 digits. I would like that when it was not 9 (111 for example) the system automatically replaced with 000000111.

The examples I found on the internet put to fill fixed numbers on the left, I can not use them since I can receive 11 and it would have to appear 000000011.

    
asked by anonymous 05.09.2017 / 21:12

1 answer

2

I believe the PadLeft would solve for your case:

Dim pad As Char
str = "11"
pad = "0"c
Console.WriteLine(str.PadLeft(11, pad)) 

Another possibility found in this answer :

Console.WriteLine(string.Format("{0:00000000000}", 11));
    
05.09.2017 / 21:17