sa*************@googlemail.com wrote:
I can't figure out how to parse the following string and to decompose
it into substring.
CuttingFlags--C500F2*#C503F3*#C509F10*#C506F2*F15##
Basically, each C should go in an array. and for each C I should have
an array of F.
CuttingFlags array contains C500, C503, C509 and C506
C500 contains F2, C506 contains F2 and F15.....
Can you help to parse the string first ?
I believe the following should do the trick:
var str = 'C500F2*#C503F3*#C509F10*#C506F2*F15##';
var spl = str.split('#');
var results = new Array();
for (i=0; i<spl.length; ++i) {
if (spl[i] && spl[i] != '') {
var k = spl[i].split('F');
k[0] = k[0].replace(/^C/,'');
results[k[0]] = 'F'+k[1];
for (j=2; j<k.length; ++j) {
results[k[0]]+='F'+k[j];
}
}
}
for (i=0; i<results.length; ++i) {
if (results[i] && results[i]!='') {
var es = results[i].split('*');
document.writeln('<hr><big>C'+i+' contains:</big><br>');
for (j=0; j<es.length; ++j) {
if (es[j] && es[j]!='') {
document.writeln(es[j]+'<br>');
}
}
}
}
Hope this helps,
--
Bart