Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
how to extract the date from string?
QString str =" get locomovements for 22455 on 16/11/2018";
QStringList list = str.split();
int LocoId = list.at(3).toInt();
how to extract 16/11/2018 from above string?
if any one know please help to get this.
JonB last edited by JonB
The way you've done it already, isn't it just
You should (probably/perhaps) use "regular expressions", http://doc.qt.io/qt-5/qregularexpression.html, for this.
If you really mean you want to parse that string to get a date, look at http://doc.qt.io/qt-5/qdate.html#fromString-1.
Stoyan last edited by
You should specify separator for split function:
If sep is empty, split() returns an empty string, followed by each of the string's characters, followed by another empty string
QStringList list = str.split(" "); // the separator is space.
If the date is always at the end of the string and in those format, you can use this:
QDate d = QDate::fromString(str.right(10), "dd/MM/yyyy");
@JonB thanq for for ur solution.
This post is deleted!