Forum Moderators: open
while(true) {
contents += fso.readline() + "\n";
} The problem is that each time I read the file, it adds an empty line to the textarea since it has to generate the linefeed ("\n") on the readline() function; this goes for the last line in the read.
So now I want to write a function to remove the last (blank) line before I save the file and I don't know how to find the blank lines. Here's what I have so far for the function:
function removeBlankLine() {
var str = document.form1.myTextArea.value;
// need a loop of some sort to find the last line?
str = str.replace(/\n/g, ""); // instead of the quotes, trim length; one backspace?
obj.value = str;
}
var contents = null;
while(true) {
if( contents ) contents += "\n";
contents += fso.readline();
}
So, assuming contents is null, the first time through this will not add the newline, but will add the fso.readline() results. The next time, the "if( contents )" check will evaluate to true, and will add a newline, then add the fso.readline() results. That way, there will be no extra \n at the end of contents.
Alternatively, you could do this:
while(true) {
contents += fso.readline() + "\n";
}
contents = contents.substring(0,contents.length-1);
[edited by: Fotiman at 9:18 pm (utc) on Dec. 28, 2006]