473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Format function... Confused!

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
4 1046
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

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: koray | last post by:
hi everyone, in my form i have to take some date information in dd-mm-yy format. but i don't want user to use tabs while typing. for example s/he should simply type 280104 but 28/01/04 must...
3
by: Gerry Abbott | last post by:
Hi all Im in Ireland, so date format is always dd/mm/yy. It trying use query as a filter for a recordset, containing a date field, SELECT tblInspections.InspDate FROM tblInspections WHERE...
11
by: Matt | last post by:
string format formula to write a text file below is not working for me pos 1 to 10 name pos 15 to 30 lastname pos 45 to 75 job Adam smith programmer string fmt = "{1,10}{15-30}{45,75}"...
0
by: phmyhn | last post by:
I have two web pages, one is viewlarger.aspx, another one is shoppingcart.aspx. On the viewlarger.aspx, when clicking "add to cart" image button, the sub appends the id (passed from another page...
10
by: KJ | last post by:
Hello, Why does this not work? txtMoney.Text.Format("#,##0.00") If I type 100 in txtMoney, it returns #,##0.00 I have never gotten the format function to work in .NET.
4
by: postings | last post by:
Hi I have a decimal numbers showing up on my datagrid that is displaying lots of trailing zeros in the listbox. i.e. 1.000100 or 1.000000 I want to get rid of all the trailing zeros (I...
8
by: BookerW | last post by:
I have the following line of code, but i don't think i am providing the right syntax: Dim oAllEntries As New DirectoryEntry(LDAP & LDAP_DOMAIN_SERVER & LDAP_USERS, LDAP_DOMAIN & sUserName,...
5
by: sara | last post by:
I've looked at all the posts I could and don't see the solution. I am aware that the format to get a BLANK when the number is 0 is: $ #,###.00;($ #,###.00);"" But I can't, for the life of me,...
2
by: daknightuk | last post by:
Hi people, I'm working on a project where I have a MYSQL database containing a database table which has opening hours of a load of businesses in it. Each business has 4 TIME fields for each day...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.