PDA

View Full Version : Detecting the last empty line in a file



Ti_Thom
18th October 2006, 17:25
Hi,
i am writing a piece of code where i modify a file (add and remove entire lines).
The problem is that i am unable to grab the last empty line. The current code is :


QStringList file_text;
while (!in.atEnd()) {
QString line = in.readLine();
file_text.push_back(line);
}
file.close();
//processing the lines and then save


is there any way to get the last empty line ? (or at least to detect if there is one)

danadam
18th October 2006, 18:52
Well,
if (line.size() != 0) {
// do something
}
should do the job, I guess.

Tair
19th October 2006, 05:14
May be something like this:


QStringList file_text;
do {
QString line = in.readLine();
file_text.push_back(line);
} while (!in.atEnd());
file.close();
//processing the lines and then save