By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,361 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

Format function... Confused!

P: n/a
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
Apr 1 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi,

Try Format(oldstring, "0000").

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

Regards,

Cerebrus.

Apr 1 '06 #2

P: n/a

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.

Apr 1 '06 #3

P: n/a
PadLeft

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

"Simon Verona" <no****@nomail.zzz> wrote in message
news:%2****************@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

Apr 1 '06 #4

P: n/a
Oh, let me try, too :)

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

"Simon Verona" <no****@nomail.zzz> wrote in message
news:%2****************@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

Apr 1 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.