Convert 1 to "00001"?

B

Benson

Is there any easy way to convert an integer (eg. 1) to a embeded zero string
(eg. 00001)?

Benson
VB2005
 
S

Sergio E.

i think that the following 2 lines must do de trick

Dim s As String = String.Empty

s.PadLeft(5, "0"c)



Best regards,

Sergio E.
 
T

Tom Shelton

Is there any easy way to convert an integer (eg. 1) to a embeded zero string
(eg. 00001)?

Benson
VB2005
Console.WriteLine (String.Format ("{0:00000}", 1))

HTH
 
G

Greg

Benson said:
Is there any easy way to convert an integer (eg. 1) to a embeded zero
string (eg. 00001)?

Dim i As Integer = 1
Dim s As String

s = i.ToString.PadLeft(5,"0")

Cheers.
 
G

gadgeteer

Was supposed to be 2 lines. Posted before I was finished editing.

Dim x As Int32 = 1
Debug.Print(x.To String("DO"))
 
G

gadgeteer

Spellchecker goofed up the code. I think you get the point but here it is
again just for grins.
Dim x As Int32 = 1

Debug.Print(x.ToString("D5"))
 
C

ClayB

Might as well make this comment too.

This syntax works as well.

1.ToString("000000")

==============
Clay Burch
Syncfusion, Inc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top