Zeros on the left

Asked

Viewed 577 times

2

I’ll be getting multiple numbers that can be up to nine digits. I would like when it was not 9 (111 for example) the system to automatically replace with 000000111.

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

1 answer

2

I believe that 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));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.