I would like to multiply the 2nd number after a Ptn: field by tfactor (already calculated) and replace it. Thus far I have
Code:
if ((lines[i].search("|MPC|Controller:tempo") == -1))
continue;
result = lines[i].match(/Pt1:\d+,(\d+)/);
if (result != null) {
old_tempo = result[1];
new_tempo = Math.round(old_tempo * tfactor);
lines[i] = lines[i].replace(old_tempo,new_tempo); }
else
continue;
result = lines[i].match(/Pt2:\d+,(\d+)/);
if (result != null) {
old_tempo = result[1];
new_tempo = Math.round(old_tempo * tfactor);
lines[i] = lines[i].replace(old_tempo,new_tempo); }
else
continue; //...... similar code for 3 & 4 follows
There will be from 1 to 4 Pts, if one is missing there will not be a next one.
My problem is I replace the first occurrence of any number I find and for certain factors (2 in this case) it could change an already converted number and leave other fields in the record alone. I could split the line on commas to change the first number I find but can't be certain if there are no other commas elsewhere on the line.
Many thanks! Just what I needed. I knew it needed something involving regular expressions and making a substitution at only specific places, but i didn't know where to begin except for an awkward workaround.
I credit you on the final version (link on 1st message).
Bookmarks