I am using QString::remove(QString)
to remove a specific line from a string, but there's a small problem which is the removed string isn't really removed, it is replaced with an empty string instead. I want to remove the whole line completely.
Original String:
...
Hi there,
Alaa Joseph is here!
The above line is going to be removed :P
It's the magic of C++ :]
...
Here's what I've tried:
test1 = originalString.replace("Alaa Joseph is here!", "");
test2 = originalString.remove("Alaa Joseph is here!"); // Same result as the previous
Output:
...
Hi there,
The above line is going to be removed :P
It's the magic of C++ :]
...
As you see above, it has removed the text without removing the whole line!
I need the output to be like this:
...
Hi there,
The above line is going to be removed :P
It's the magic of C++ :]
...
I know I could just iterate through each line & do this:
QStringList list = test1.split("\n");
list.removeAt(0);
int n = list.length();
list.removeAt(n - 1);
QString noEmptyLines = list.join("\n");
But I don't want to remove all empty lines, only ones which I removed their content as this will ruin the whole format of my document.