|
-
June 13th, 2001, 09:26 AM
#1
Pad a String
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)
-
June 13th, 2001, 09:33 AM
#2
Re: Pad a String
not that I know of, I do write my own.
HTH
cksiow
http://vblib.virtualave.net - share our codes
-
June 13th, 2001, 09:36 AM
#3
Re: Pad a String
A one line solution is
Strng = "A"
NewStr = StrReverse(Left$(Strng & String$(4, "0"), 4))
-
June 13th, 2001, 09:38 AM
#4
Re: Pad a String
Sorry, a slight amendment
Strng = "AB"
NewStr = StrReverse(Left$(StrReverse(Strng) & String$(4, "0"), 4))
-
June 13th, 2001, 09:46 AM
#5
Re: Pad a String
sString = "A"
msgbox Format(sString,"0000") -> will give you "000A"
Iouri Boutchkine
[email protected]
-
June 13th, 2001, 09:48 AM
#6
-
June 13th, 2001, 10:39 AM
#7
Re: Pad a String
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]
-
June 14th, 2001, 01:13 AM
#8
Re: Pad a String
I have tried this, but get "A" and not "000A" ????
-
June 15th, 2001, 02:22 PM
#9
Re: Pad a String
Try
msgbox Format$(sString,"0000")
Iouri Boutchkine
[email protected]
-
June 15th, 2001, 02:38 PM
#10
Re: Pad a String
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]
-
June 18th, 2001, 12:45 AM
#11
Re: Pad a String
Sorry - I have tried this, but still get "A" and not "000A" ?
Does it work in your environment that way?
-
June 18th, 2001, 03:13 AM
#12
Re: Pad a String
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.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
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
|