1

What is the easiest way to do this?

I have a string like this.

var string='0ABAFFACBDFE...';

I want to convert it to this.

var newString= '0A,BA,FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..FF,AC,BD,FE ..';
iConnor
  • 19,997
  • 14
  • 62
  • 97
user2061745
  • 305
  • 2
  • 3
  • 12
  • See this http://stackoverflow.com/questions/7033639/javascript-split-large-string-in-n-size-chunks and use `join` – Dave Oct 13 '13 at 18:08

1 Answers1

5

Maybe something like

string.match(/.{1,2}/g).join(',');

Split the string by 2 chars, into an Array, then join the array back into a string with the comma on the end of every string in the array.

iConnor
  • 19,997
  • 14
  • 62
  • 97