Hello. I have a simple problem and need help. I am developing a simple
file system that stores info based on folder names. Now, I only have
one problem. How do i format (int i = 2) into a string like "00002"
instead of the defualt "2"? 5 27694
On 7 Jan 2007 10:13:16 -0800, "Code::Tyr" <le*******@gmail.comwrote:
>Hello. I have a simple problem and need help. I am developing a simple file system that stores info based on folder names. Now, I only have one problem. How do i format (int i = 2) into a string like "00002" instead of the defualt "2"?
Console.WriteLine("Like this: {0:D5}", 2);
alternatively:
Console.WriteLine("Like this: " + 2.ToString("00000"));
rossum
Code::Tyr wrote:
Hello. I have a simple problem and need help. I am developing a simple
file system that stores info based on folder names. Now, I only have
one problem. How do i format (int i = 2) into a string like "00002"
instead of the defualt "2"?
private static string AppendZerosBeginning(int input, int length)
{
return input.ToString().PadLeft(length, Convert.ToChar("0"));
}
If the numeric values are coming out of SQL Server, you can also use
the REPLICATE keyword in your select statement to pad the int with
leading zeros: http://sqlblogcasts.com/blogs/tonyro...05/29/765.aspx bo**********@cox.net wrote:
Code::Tyr wrote:
>Hello. I have a simple problem and need help. I am developing a simple file system that stores info based on folder names. Now, I only have one problem. How do i format (int i = 2) into a string like "00002" instead of the defualt "2"?
private static string AppendZerosBeginning(int input, int length)
{
return input.ToString().PadLeft(length, Convert.ToChar("0"));
}
There are already posted much better solutions.
Arne
How about a variation:
private static string AppendZerosBeginning(int input, int length)
{
return input.ToString(new string("0", length));
}
<bo**********@cox.netwrote in message
news:11**********************@42g2000cwt.googlegro ups.com...
>
Code::Tyr wrote:
>Hello. I have a simple problem and need help. I am developing a simple file system that stores info based on folder names. Now, I only have one problem. How do i format (int i = 2) into a string like "00002" instead of the defualt "2"?
private static string AppendZerosBeginning(int input, int length)
{
return input.ToString().PadLeft(length, Convert.ToChar("0"));
}
If the numeric values are coming out of SQL Server, you can also use
the REPLICATE keyword in your select statement to pad the int with
leading zeros:
http://sqlblogcasts.com/blogs/tonyro...05/29/765.aspx
Thanks, all!
Stephany Young wrote:
How about a variation:
private static string AppendZerosBeginning(int input, int length)
{
return input.ToString(new string("0", length));
}
<bo**********@cox.netwrote in message
news:11**********************@42g2000cwt.googlegro ups.com...
Code::Tyr wrote:
Hello. I have a simple problem and need help. I am developing a simple
file system that stores info based on folder names. Now, I only have
one problem. How do i format (int i = 2) into a string like "00002"
instead of the defualt "2"?
private static string AppendZerosBeginning(int input, int length)
{
return input.ToString().PadLeft(length, Convert.ToChar("0"));
}
If the numeric values are coming out of SQL Server, you can also use
the REPLICATE keyword in your select statement to pad the int with
leading zeros: http://sqlblogcasts.com/blogs/tonyro...05/29/765.aspx This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Krakatioison |
last post by:
My sites navigation is like this:
http://www.newsbackup.com/index.php?n=000000000040900000
, depending on the variable "n" (which is always a number), it will take me
anywhere on the site......
|
by: Stian |
last post by:
Hi, I'm sort of new to Python and I've just discovered the amazing
formatting using the % operator. One thing I can't figure out is how
to format numbers so that they get leading zeros, for example...
|
by: cody |
last post by:
How can I format numbers with leading zeros? I believe I did this before
some time ago but I cannot remember how I did it.
I want the output be 100305 for 10:03:05.
string fname =...
|
by: Ingo Nolden |
last post by:
Hello,
I want to format floats ( doubles ) into small strings of 7 characters.
I tried to use std::ostream, but I don't get the desired behaviour.
Especially in scientific notation I am not...
|
by: Dave Brydon |
last post by:
Access 2003
I have a combo box in my personnel table, which draws its data from a trade
code table; the original field in the code table, is numeric, Long Integer,
and formatted with 5 zero's . ...
| |
by: Bilgehan.Balban |
last post by:
Hi,
I use %#08x to print unsigned integers in hexadecimal format. According
to C ref. man. Harbison & Steele, #08 stands for "pad the number with
up to 8 zeroes to complete it to 8 digit...
|
by: chris |
last post by:
Hi,
I have a simple ms access application that allows you to scan barcodes
in to a form which stores them in the database. The barcodes are 6
digits in length e.g. 555666 but my handheld...
|
by: Vlinder |
last post by:
I'm completely new to PHP (jumped ship this week from MSAccess and ASP to MySql and PHP) and I'd appreciate some help with leading zeros in telephone numbers.
I've got a field with type...
|
by: lawpoop |
last post by:
Hello all --
I'm trying to format decimal numbers for a report. I would have to
have the number with leading zeros to the tens' place, and trailing
zeros to the thousandths' place.
I'm using...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |