javascript - how to extract tuples string into data structure? -


this question has answer here:

i new here. trying change following tuple multi-dimensional array in javascript. tuple string: str: "(4,7,1),(8,9,6),(3,5,7)". can think of doing loop. looking sufficient way this. 1 way use regex in javascript. not in regular expression. me please? in advance!

you can parse yourself. here's 1 way in working snippet:

function parsetuple(t) {      var items = t.replace(/^\(|\)$/g, "").split("),(");      items.foreach(function(val, index, array) {         array[index] = val.split(",").map(number);      });      return items;  }    var data = "(4,7,1),(8,9,6),(3,5,7)";  var result = parsetuple(data);  document.write(json.stringify(result));


you use json.parse() parsing converting tuple string legal json this:

function parsetuple(t) {      return json.parse("[" + t.replace(/\(/g, "[").replace(/\)/g, "]") + "]");  }    var t = "(4,7,1),(8,9,6),(3,5,7)";  var result = parsetuple(t);  document.write(json.stringify(result));


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -