Board index » Visual Studio » creating a string from a character and integer with leading zeros

creating a string from a character and integer with leading zeros

Visual Studio313
Hello there

I have a couple of questions which I hope somebody will help me with.

First, in VBscript, I used to use the function "string", which will take an

integer and a character, then creates a string of the character with the

integer as the length of this string.

Need to do the same with VB.net.

I also want to display an integer with leading zeros, with a defined length.

Example, 43 appears as 00043 when the length is 5 and 000043 when the length

is 6.

Any ideas will be appreciated.

Regards

Sameh


-
 

Re:creating a string from a character and integer with leading zeros

* "Sameh Ahmed" <essoplus@hotmail.com>scripsit:

Quote
I have a couple of questions which I hope somebody will help me with.

First, in VBscript, I used to use the function "string", which will take an

integer and a character, then creates a string of the character with the

integer as the length of this string.

Need to do the same with VB.net.



It's called 'StrDup' in VB.NET.



Quote
I also want to display an integer with leading zeros, with a defined length.

Example, 43 appears as 00043 when the length is 5 and 000043 when the length

is 6.



\\\

Dim s As String = Format(43, "000000")

///



--

Herfried K. Wagner [MVP]

<URL:dotnet.mvps.org/>">dotnet.mvps.org/>

-

Re:creating a string from a character and integer with leading zeros

Sameh,

In addition to the Format function. You can use Integer.ToString to have the

same the same effect.



Dim i As Integer = 45

Dim s As String

s = i.ToString("D5")

s = i.ToString("D4")



Hope this helps

Jay



"Sameh Ahmed" <essoplus@hotmail.com>wrote in message

Quote
Hello there

I have a couple of questions which I hope somebody will help me with.

First, in VBscript, I used to use the function "string", which will take

an

integer and a character, then creates a string of the character with the

integer as the length of this string.

Need to do the same with VB.net.

I also want to display an integer with leading zeros, with a defined

length.

Example, 43 appears as 00043 when the length is 5 and 000043 when the

length

is 6.

Any ideas will be appreciated.

Regards

Sameh









-