473,382 Members | 1,396 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,382 software developers and data experts.

String Format Question

Hi,

A quick one for someone hopefully.....

How do I return a string "003" from the integer 3 ?

I believe its something like:

int tempval = 3;
string tempstr = String.Format("{0???}",tempval);

??? = Thats where I am stuck !

I dont find the Help particuarly helpfull on this one

Any ideas please,

Thanks in advance

Jon
Aug 16 '06 #1
4 3982

Bishman wrote:
Hi,

A quick one for someone hopefully.....

How do I return a string "003" from the integer 3 ?

I believe its something like:

int tempval = 3;
string tempstr = String.Format("{0???}",tempval);

??? = Thats where I am stuck !

I dont find the Help particuarly helpfull on this one

Any ideas please,

Thanks in advance

Jon
string tempstr = tempval.ToString ("000");

Hope that helps,

Nick
http://seecharp.blogspot.com/

Aug 16 '06 #2

nick_nw wrote:
Bishman wrote:
Hi,

A quick one for someone hopefully.....

How do I return a string "003" from the integer 3 ?

I believe its something like:

int tempval = 3;
string tempstr = String.Format("{0???}",tempval);

??? = Thats where I am stuck !

I dont find the Help particuarly helpfull on this one

Any ideas please,

Thanks in advance

Jon

string tempstr = tempval.ToString ("000");
Or, you can use:

string tempstr = String.Format ("{0:000}", tempval);

See http://idunno.org/displayBlog.aspx/2004071401 for a handy list of
string fomatting examples.

Best,

Nick
http://seecharp.blogspot.com/

Aug 16 '06 #3
Perfect, Good link,

Thanks Nick.
"nick_nw" <ng****@gmail.comwrote in message
news:11**********************@74g2000cwt.googlegro ups.com...
>
nick_nw wrote:
>Bishman wrote:
Hi,

A quick one for someone hopefully.....

How do I return a string "003" from the integer 3 ?

I believe its something like:

int tempval = 3;
string tempstr = String.Format("{0???}",tempval);

??? = Thats where I am stuck !

I dont find the Help particuarly helpfull on this one

Any ideas please,

Thanks in advance

Jon

string tempstr = tempval.ToString ("000");

Or, you can use:

string tempstr = String.Format ("{0:000}", tempval);

See http://idunno.org/displayBlog.aspx/2004071401 for a handy list of
string fomatting examples.

Best,

Nick
http://seecharp.blogspot.com/

Aug 16 '06 #4
Hello Bishman,

Try "000" instead of "0???"
Regards
Cyril Gupta

You can do anything with a little bit of 'magination.
I have been programming so long, that my brain is now soft-ware.
http://www.cyrilgupta.com/blog
Hi,

A quick one for someone hopefully.....

How do I return a string "003" from the integer 3 ?

I believe its something like:

int tempval = 3;
string tempstr = String.Format("{0???}",tempval);
??? = Thats where I am stuck !

I dont find the Help particuarly helpfull on this one

Any ideas please,

Thanks in advance

Jon

Aug 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Trevor Balcom | last post by:
Hello, I am new to C# and cannot figure out how to do something simple. How can I build two strings out of a DateTime object? I need one string to contain the DateTime's date in YYMMDD format. ...
7
by: Roger Helliwell | last post by:
Hello Everyone, Has anyone found a quick reference for the many string formatting options for string.Format() ? I'm spending a ridiculous amount of time trying to write one line of code that...
2
by: Donald | last post by:
I am trying print the length of a managed array, but I cannot figure out how to correctly cast the result so String::Format will use it. I wrote a simple test to duplicate the problem (below) --...
2
by: Akeel | last post by:
Hi I have the following code char splitter={','}; string fields=row.ToString().Split(splitter) string serviceDefintion="" // row.ToString().Split(splitter // conatins the followin...
0
by: Cat | last post by:
Hello. I have an integer whose value varies from 0 to 9999. I want to print it in a four-digit format. Like, 0000 0001 0002 ..... 9998 9999
0
by: Amir | last post by:
hey every one i had a question i have a page where i display employees profiles this page calle profile.aspx is only accessable by admins and has an ifram where points to deatils.aspx now i...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.