Ok, I can write it my own, but is there a VB function to 'left pad' a string?
e.g. "A" -> "000A"
something like: LeftPad("A","0",4)
Printable View
Ok, I can write it my own, but is there a VB function to 'left pad' a string?
e.g. "A" -> "000A"
something like: LeftPad("A","0",4)
not that I know of, I do write my own.
HTH
cksiow
http://vblib.virtualave.net - share our codes
A one line solution is
Strng = "A"
NewStr = StrReverse(Left$(Strng & String$(4, "0"), 4))
Sorry, a slight amendment
Strng = "AB"
NewStr = StrReverse(Left$(StrReverse(Strng) & String$(4, "0"), 4))
sString = "A"
msgbox Format(sString,"0000") -> will give you "000A"
Iouri Boutchkine
[email protected]
You're always better...
Don't be shy. We all have something to learn from you.
By the way welcome in VBCodeLibrary Forum.
Good luck.
Iouri Boutchkine
[email protected]
I have tried this, but get "A" and not "000A" ????
Try
msgbox Format$(sString,"0000")
Iouri Boutchkine
[email protected]
Anptherr solution
Dim s As String
Dim sLeadingZeroes As String
sLeadingZeroes = "0000"
s = "A"
MsgBox Left(sLeadingZeroes, Len(sLeadingZeroes) - Len(s)) & s
Iouri Boutchkine
[email protected]
Sorry - I have tried this, but still get "A" and not "000A" ?
Does it work in your environment that way?
Try This:
Dim mytext as string * 4
RSet mytext = Text1.Text
mytext = Replace(mytext, " ", "0")
Text1.Text = mytext
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.