1

How I can isolate value of string (00010111001101000001011100011001) on strings by number of characters(8) use jquery and javascript?

I want this: Result: [ "00010111", "00110100", "00010111", "00011001" ]

2 Answers2

1

You can use .match (with regexp \d{8}/g ) function which returns all characters(8)

console.log("00010111001101000001011100011001".match(/\d{8}/g));
Oleksandr T.
  • 76,493
  • 17
  • 173
  • 144
  • Important to point out is that the rest of the string will be discarded (ignored) if the length of the string is not a multiple of `8`. – Felix Kling Feb 28 '15 at 22:32
0

Use substring:

var s = "00010111001101000001011100011001"; 
var v = new Array();
for ( i = 0 ; i < s.length ; i+=8 ) {
    v[i/8] = s.substring(i,i+8);
}    
console.log(v);

Output:

["00010111", "00110100", "00010111", "00011001"]
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199