473,507 Members | 2,545 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 1544
Try

foo.ToString("0000").

Cheers,
B

"Hai Nguyen" <ha******@neo.tamu.edu> wrote in message
news:O9**************@TK2MSFTNGP12.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.PadLeft
____________________________________
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
DigitallySmooth Inc. | Quick Site Studio
"Hai Nguyen" <ha******@neo.tamu.edu> wrote in message news:O9**************@TK2MSFTNGP12.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.tamu.edu> wrote in message
news:O9**************@TK2MSFTNGP12.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
36792
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...
7
6483
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...
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...
4
1623
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...
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...
7
3086
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
2305
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
4980
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...
3
1871
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
9000
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...
0
7223
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
7314
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,...
0
7372
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...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5623
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,...
1
5041
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
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...
0
1540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
411
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...

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.