0

I need help with string.format to insert three spaces every three digit. This digit is at a fixed length at 12 digits.

var membershipNo = string.Format("{0:### ### ### ###}", "123123123123");
Console.WriteLine(membershipNo);

Result: 123123123123

Expected: 123 123 123 123

2
  • 2
    0:### ### ### ### is a numeric format string, not a string format. Where are the digits in membershipNo coming from? If they're always digits why are you storing them as a string not an long? Commented Mar 12, 2019 at 22:03
  • Also - what result you expect for "000123123123"? Commented Mar 12, 2019 at 22:09

1 Answer 1

4

This type of formating doesn't work for an instance of string. Consider passing an interger (or any other numeric type) and it will work as expected

int number = 123123123123;
var membershipNo = string.Format("{0:### ### ### ###}", number);
Console.WriteLine(membershipNo);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.