How do I add "123" to the beginning of a string and pad it to be exactly 12 chars?
Well, you could use:
string result = "123" + text.PadLeft(9, '0');
In other words, split the task in half - one part generating the "000028431", "000000987" etc part using string.PadLeft
, and the other prefixing the result with "123" using simple string concatenation.
There are no doubt more efficient approaches, but this is what I'd do unless I had a good reason to believe that efficiency was really important for this task.
var result = string.Format("123{0}", number.PadLeft(9, '0'));
You could try:
var str = String.Format("123{0:0#########}", 28431);
or
var str = String.Format("123{0:000000000}", 28431);