Unsolved Getting the fourth line QString
-
hi ,
I want to get the fourth line of a text inside QStringQString str = "1 \n 2 \n 3 \n 4 \n 5 \n 6 \n";
-
Quite simply use
foostring.split()...
Split and pass the argument as a char of a linebreak.
Then from the qstringlist the resulting indexes should be your line -
@MrErfan
QStringList list = str.split("\n");
return list[3];Have a look at the overloads of http://doc.qt.io/qt-5/qstring.html#split to decide just what you want to split on, e.g. perhaps a
QRegExp
.EDIT: P.S.
split()
does not scale optimally if you have, say, a million+ lines instr
--- let us know if that is a possible factor ;-)