Reputation: 305
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 ..';
Upvotes: 1
Views: 93
Reputation: 20199
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.
Upvotes: 5