.replace method not consistent
The function prepVerse is bound to an event handler "onchange" for a textarea and this works fine. Any time there is any change to the textarea the function reads the textarea into an array. The code steps through the array and:
1. removes blank and null lines.
2. strips line number
3. assigns new line number
4.append \n to end of line
5.appends current line to outBuffer
6. outBuffer moved back to textarea.
On the first iteration the works fine, however the next iteration outbuffer is blank.
if I take out the .replace(/[0-9]+/g,"") every thing works fine with no lost data(but does have redundant l line numbers.)
Please comment
- function prepVerse(){
var outBuffer="";
var sanitizeThis=($(this).val().split('\n'))
$(this).val("");
//alert( sanitizeThis.length);
for(var i = 0; i < sanitizeThis.length; i++){
if(sanitizeThis[i]==""||sanitizeThis[i]==null){
sanitizeThis.splice(i,1);
}//end if
outBuffer=outBuffer+i+sanitizeThis[i].replace(/[0-9]+/g,"")+"\n";<------Problem is here
}//end for
alert(outBuffer);
$(this).val(outBuffer);
}//End prepVerse