473,666 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String.Format?? ??

Hi everyone I have a textbox which acts like a counter. I want to format the
number in 4 digits; for instance,
1 -> 0001
10 -> 0010

Is there anyway I can do that?

Thanks
Nov 18 '05 #1
3 1549
Try

foo.ToString("0 000").

Cheers,
B

"Hai Nguyen" <ha******@neo.t amu.edu> wrote in message
news:O9******** ******@TK2MSFTN GP12.phx.gbl...
Hi everyone I have a textbox which acts like a counter. I want to format the number in 4 digits; for instance,
1 -> 0001
10 -> 0010

Is there anyway I can do that?

Thanks

Nov 18 '05 #2
Use PadLeft
if your textbox is named Textbox1:

Textbox1.Text.P adLeft
_______________ _______________ ______
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
DigitallySmooth Inc. | Quick Site Studio
"Hai Nguyen" <ha******@neo.t amu.edu> wrote in message news:O9******** ******@TK2MSFTN GP12.phx.gbl...
Hi everyone I have a textbox which acts like a counter. I want to format the
number in 4 digits; for instance,
1 -> 0001
10 -> 0010

Is there anyway I can do that?

Thanks
Nov 18 '05 #3
String.Format(" {0:0000}", strMyString);

As always, at least 3 ways to do anything in MS code.

MIke
"Hai Nguyen" <ha******@neo.t amu.edu> wrote in message
news:O9******** ******@TK2MSFTN GP12.phx.gbl...
Hi everyone I have a textbox which acts like a counter. I want to format the number in 4 digits; for instance,
1 -> 0001
10 -> 0010

Is there anyway I can do that?

Thanks

Nov 18 '05 #4

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

Similar topics

2
36837
by: Bob | last post by:
I'm having trouble the string.Format() throwing exceptions and I can't figure out what I am doing wrong. Given the following setup code: string str = { "one", "two", "three", "four" }; double val = { 1.0, 2.0, 3.0, 4.0 }; string fmt = "{0} {1} {2} {3}"; The following variations of string.Format() will work just fine with strings: string s1 = String.Format(fmt, str, str, str, str); // works
7
6490
by: Alpha | last post by:
Hi, I'm maintaining C# code and am fairly new with C# programming. I'm looking for codes that's droping the 2nd digit of a nuber printed out and I suspect it's the code below. Can someone tell me where I can look up explaination on the String.Format, the format string part like "("{0:.#0}". What's the trailing 0 and what is that "0:" means? I assume the "#" is the place holder character for th value obtain after the comma in the code. ...
3
485
by: Dominique Vandensteen | last post by:
after the very small & vs string.format discussion I did some speed tests... loop of 1.000.000 concatenations of 5 public string variables in a class gave following results: result = a & b & c & d & e +/- 420ms
4
1630
by: David Morris | last post by:
Hi Could somebody please explain what the following line of code means String.Format("{0}\{1}.{2:00}", C:\, myfile.txt, 1 It's actually the first argument that I don't understand. What is the purpose of "{0}\{1}.{2:00}"? I've been using VB .NET for a year now, and have never come across anything like this Best Regards David Morris
38
807
by: nobody | last post by:
I know that given a FormatString and a DateTime you can use DateTime.ToString(...) to convert the DateTime to a String. My question is how can you turn that around? Given a String and a FormatString, how can you convert the String back to a DateTime? DateTime.Parse(...) doesn't use the FormatString. Now admitedly, if the format string is just "MM", it can't be done. But if the format string is "yyyyMMdd", or "ddMMMyyyy hhmmsst", it...
7
3106
by: L. Scott M. | last post by:
Have a quick simple question: dim x as string x = "1234567890" ------------------------------------------------------- VB 6 dim y as string
5
2314
by: AMP | last post by:
Hello, I want to add some variables to a string and this isnt working. textBox1.Text="'BSL version='+ bslVerHi+ bslVerLo"; What am I doing wrong? Thanks Mike
8
4990
by: Lucky | last post by:
hi guys! back again with another query. the problem is like this. i want to print a line like this: "---------------------------------------------" the easiest way is to simply assign it to string and print it. but i want to use the String.Format() method if possible to do it.
3
1876
by: shawrie | last post by:
Hello everyone can anyone please help me? I basically want to set the length of a string variable to help spacing my simple report out. i tried dim test as string(14) but it didnt like that
5
9017
by: jpenguin | last post by:
I'm doing a simple program to learn java. I have the input and math parts right. It just isn't displaying right. It outputs a list of about 11 things-- with the format "string $ xx.xx" In each line the '$'s should be aligned and the decimal point should be aligned. This is what it currently shows-http://img140.imageshack.us/img140/2684/screenshot20090910at357.jpg package excercise6; import java.swing.*; /** * * @author dye1107...
0
8445
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8871
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7386
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.