Format function... Confused!

  • Thread starter Thread starter Simon Verona
  • Start date Start date
S

Simon Verona

I'm a little confused

I have a string that contains a number eg 11 that I want to format into a 4
character string with leading zeros ie 0011

I guess I need to use the "format" function.... ie
newstring=format(oldstring,"????")

What goes in as the format conversion to get the affect I want?

Thanks in advance
Simon

--
================================
Simon Verona
Dealer Management Service Ltd
Stewart House
Centurion Business Park
Julian Way
Sheffield
S9 1GD

Tel: 0870 080 2300
Fax: 0870 735 0011
 
Hi,

Try Format(oldstring, "0000").

For more information refer to the "User-defined Numeric Formats" topic
of the Format function.

Regards,

Cerebrus.
 
Simon Verona wrote:
I have a string that contains a number eg 11 that I want to format into a 4
character string with leading zeros ie 0011

I guess I need to use the "format" function.... ie
newstring=format(oldstring,"????")
<snip>

Instead of Format, you may use PadLeft method of the String type:

NewString = OldString.PadLeft(4, "0"c)

This will return a string with 4 or less "0" to the left: "1" ->
"0001"; "12" -> "0012", etc.

Regards,

Branco.
 
Oh, let me try, too :)

Dim i As Integer = 11
Dim s As String = i.ToString("d4")


Kelly
 
Back
Top