Reputation: 905
I know this should be an easy thing but I don't know how to do it.
I want to insert some data into a table, and I'm using loops because I have over 1million datas to insert. It should look like this "PM-0000000000, PM-0000000001......... PM-0000099999"
. Now here's the problem. I don't know how to add those zeros in front according to the numbers that are after the zeros. the number length (PM-"0000000000"
) Should always be 10.
Help please ?
Upvotes: 1
Views: 248
Reputation: 63105
you can generate full code using string.Format
string.Format("PM-{0:D10}", intval)
Upvotes: 2
Reputation: 109862
You can do string result = number.ToString("0000000000");
But I prefer @Kasyx's answer above. (I added this answer for completeness.)
Upvotes: 4
Reputation: 3200
Please check this documentation: http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx#DFormatString
int yourNumber = 999;
string filledNumber = yourNumber.ToString("D10");
Where D10
means, your number will be filled to 10 digits.
Upvotes: 5
Reputation: 11063
Use padleft to fill the string with the number of zeros you need
string value="99999";
string concat= "PM" + value.PadLeft(10, '0');
Upvotes: 5