I need to add "123" and zeros for any string – but the resulting string must be exactly 12 characters long.
For example:
28431 = 123000028431
987 = 123000000987
2 = 123000000002
How to do this in C#?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, you could use:
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.