Given that ccnum is a 16-character string containing only numbers (credit card number), I want to format the string nicely with 4 digits at a time, separated by spaces. I tried this:
ccnum=ccnum.substring(0, 4)+' '+
ccnum.substring(4, 4)+' '+
ccnum.substring(8, 4)+' '+
ccnum.substring(12, 4);
But I get unpredictable results, such as:
12341234 1234 1234
1234 1234 12341234
Not sure why?