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

Quick ToString() Question

Hello,

I have a number that I am looking to change into a
string, but when I do this it has to add zeros to make
the string long enough. I am looking to have the string
be seven chars long no matter what the number is (it's
never over 9999999):

int string
999 "0000999"
12343 "0012343"

What string would I pass to the Int32's ToString("")
method to do this? Thanks!
Nov 18 '05 #1
3 1020
You are looking for string.padleft
be something like...
yourInt32Var.toString.PadLeft(7,"0")

"Mark Fox" <in**@solelsoftware.com> wrote in message
news:01****************************@phx.gbl...
Hello,

I have a number that I am looking to change into a
string, but when I do this it has to add zeros to make
the string long enough. I am looking to have the string
be seven chars long no matter what the number is (it's
never over 9999999):

int string
999 "0000999"
12343 "0012343"

What string would I pass to the Int32's ToString("")
method to do this? Thanks!

Nov 18 '05 #2
The string object has a method called "PadLeft" which allows you to pad the
left side of a string with a specified unicode character.

So, you could use:

int number = 999;
string paddedNumber = number.ToString().PadLeft(7, Convert.ToChar("0"));

paddedNumber would then contain "0000999"

Hope this helps,

Mun

"Mark Fox" <in**@solelsoftware.com> wrote in message
news:01****************************@phx.gbl...
Hello,

I have a number that I am looking to change into a
string, but when I do this it has to add zeros to make
the string long enough. I am looking to have the string
be seven chars long no matter what the number is (it's
never over 9999999):

int string
999 "0000999"
12343 "0012343"

What string would I pass to the Int32's ToString("")
method to do this? Thanks!


Nov 18 '05 #3

Thanks so much. That's what I was looking for!
-----Original Message-----
The string object has a method called "PadLeft" which allows you to pad theleft side of a string with a specified unicode character.

So, you could use:

int number = 999;
string paddedNumber = number.ToString().PadLeft(7, Convert.ToChar("0"));
paddedNumber would then contain "0000999"

Hope this helps,

Mun

"Mark Fox" <in**@solelsoftware.com> wrote in message
news:01****************************@phx.gbl...
Hello,

I have a number that I am looking to change into a
string, but when I do this it has to add zeros to make
the string long enough. I am looking to have the string be seven chars long no matter what the number is (it's
never over 9999999):

int string
999 "0000999"
12343 "0012343"

What string would I pass to the Int32's ToString("")
method to do this? Thanks!


.

Nov 18 '05 #4

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

Similar topics

2
by: Rudy | last post by:
Hello all! Have a quick question on drop down list. Need to make a year ddl, 1900 to 1987. Is there a quick way to do this. I'm not binding this, just loading it in the items collection. ...
7
by: jimi_xyz | last post by:
I am kind of new to C sharp; I have a quick question I have multiple text boxes 12 of them to be exact. What I want to do is fill them with values that are in a array of integers. The way I am...
3
by: Gary | last post by:
f.CreationTime.Hour.ToString() + ":" + f.CreationTime.Minute.ToString() + ":" + f.CreationTime.Millisecond.ToString(); Which produces a format like 9:30:124 Now I'd like to change this...
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: 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?
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
tracyyun
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...
0
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,...
0
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...

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.