Reputation: 67
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
Upvotes: 0
Views: 93
Reputation: 9632
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);
Upvotes: 4