Tuesday, 17 September 2013

How does String.Format work in this situation

How does String.Format work in this situation

I have a website where you can buy stuff, and we want to format the
orderID that goes to our portal in certain way. I am using the
string.format method to format it like this:
Portal.OrderID = string.Format("{0}{1:0000000}-{2:000}", "Z"
,this.Order.OrderID, "000");
So we want it to look like this basically Z0545698-001. My question is, if
I am using string.format will it blow up if this.Order.OrderID is greater
than 7 characters?
If so, how can I keep the same formatting (i.e. Z 1234567 - 000) but have
the first set of numbers (the 1-7) be a minimum of 7 (with any numbers
less than 7 in length have leading 0's). And then have anything greater
than 7 in length just extend the formatting so I could get an order number
like Z12345678-001?

No comments:

Post a Comment