|
-
Sep 16th, 2009, 02:16 PM
#1
Thread Starter
Addicted Member
VB2008 fixed string and fill the rest with zeros
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?
-
Sep 16th, 2009, 02:20 PM
#2
Hyperactive Member
Re: VB2008 fixed string and fill the rest with zeros
Subtract the fixed number of characters from the length of the string the user inputs.
Add the zeros that many times beforehand.
-
Sep 16th, 2009, 02:20 PM
#3
Re: VB2008 fixed string and fill the rest with zeros
You can use the PadLeft function:
Code:
Dim s As String = "TWO"
s = s.PadLeft(6, "0"c)
MessageBox.Show(s)
Last edited by Negative0; Sep 16th, 2009 at 03:09 PM.
Reason: Fixed option strict problem. How'd that get turned off?
-
Sep 16th, 2009, 02:27 PM
#4
Thread Starter
Addicted Member
Re: VB2008 fixed string and fill the rest with zeros
Thanks Negative0, I didn't know about the padleft function. worked perfectly
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|