function calculate() { var i, j, OutText = "", tempstr, postab; var lines = new Array(), result = new Array(); lines = document.nwcform.OutputField.value.split("\n"); for (i=0; i < lines.length; i++) { lines[i] = lines[i].replace(/[\t\r\f\v]/g,""); //So will run in IE if (lines[i].slice(0,15) == "|Rest|Dur:Whole") { //In case your browser puts extra characters at the end, slice ignores them. OutText += "|Rest|Dur:4th\n|Rest|Dur:4th\n|Rest|Dur:4th\n|Rest|Dur:4th\n"; } //Ends with \n. This examples adds 4 lines. else { result = lines[i].match(/^\|(Note|Chord)\|Dur:Whole(\|Pos:)(.*)$/) // result = lines[i].match(/^(\|Note\|Dur:)Whole(\|Pos:)(.*)$/) if (result != null) { postab = result[3]; postab = postab.replace(/,/g,"^,"); //Add a carat before each comma (if any--none for a note) postab += "^"; // and at the end postab = postab.replace(/\^\^/g,"^") //Replace two carots with just one tempstr= "|" + result[1] + "|Dur:4th" + result[2] + postab + "\n"; for (j = 0; j < 3; j++) { //Adds 1st three occurances with ties on all note(s) OutText += tempstr; } OutText += "|" + result[1] + "|Dur:4th" + result[2] + result[3] + "\n"; } //Last note in set as is, only changing duration else { OutText += lines[i]; if ((i+1) < lines.length) //No need to add a newline character to last line OutText += "\n"; } } } document.nwcform.OutputField.value = OutText; //Replaces original data with what was created in OutText document.nwcform.OutputField.select(); //Output is pre-selected, just Cntl/C to put on clipboard }