I need to format a string in a fixed number of characters.
For example, if someone type TWO
It has too save in the variable
000TWO
if type THREE
0THREE
Always 6 characters and fill the rest with zeros on the left.
Any idea?
Printable View
I need to format a string in a fixed number of characters.
For example, if someone type TWO
It has too save in the variable
000TWO
if type THREE
0THREE
Always 6 characters and fill the rest with zeros on the left.
Any idea?
You can use the PadLeft function:
Code:Dim s As String = "TWO"
s = s.PadLeft(6, "0"c)
MessageBox.Show(s)
Subtract the fixed number of characters from the length of the string the user inputs.
Add the zeros that many times beforehand.
Thanks Negative0, I didn't know about the padleft function. worked perfectly