I'm trying to display a credit card number as a string like #### #### #### ####
I tried:
txtbox.Text = string.Format("{0:#### #### #### ####}", ccNumber);
and it didn't work. Any ideas?
String.Format("{0:0000 0000 0000 0000}", number)
EDIT
I paste my comment here to made it readable:
ccNumber is an Int or a string? if it's an int it should work. if it's a string you need to do a
String.Format("{0:0000 0000 0000 0000}", (Int64.Parse("1234567812345678")))
I expect the string to have a space after four digits - 1234 5678 9123 4567 - and it looks like 1234567891234567.
ccNumber is an Int or a string? if it's an int it should work, if it's a string you need to do a String.Format("{0:0000 0000 0000 0000}", (Int64.Parse("1234567812345678")))
Make sure the number is not already in string format! once I converted to long, it worked as expected.
Major issue with using this though is all leading and trailing 0s will be destroyed.
@Chris Marisic String.Format only cuts leading and trailing zeros if you format with #### instead of 0000.