Home All Groups Group Topic Archive Search About

Format function... Confused!

Author
1 Apr 2006 9:26 AM
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

Author
1 Apr 2006 9:43 AM
Cerebrus
Hi,

Try Format(oldstring, "0000").

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

Regards,

Cerebrus.
Author
1 Apr 2006 3:22 PM
Branco Medeiros
Simon Verona wrote:
<snip>
> 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.
Author
1 Apr 2006 3:25 PM
Jim Hughes
PadLeft

Dim i As Integer = 11
Trace.WriteLine(i.ToString.PadLeft(4, "0"c))

Show quoteHide quote
"Simon Verona" <nom***@nomail.zzz> wrote in message
news:%239C0Z5WVGHA.5248@TK2MSFTNGP10.phx.gbl...
> 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
>
>
Author
1 Apr 2006 11:11 PM
Kell Ethridge
Oh, let me try, too :)

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


Kelly



Show quoteHide quote
"Simon Verona" <nom***@nomail.zzz> wrote in message
news:%239C0Z5WVGHA.5248@TK2MSFTNGP10.phx.gbl...
> 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
>
>