Unsolved 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. -
@bhargav
The way you've done it already, isn't it justlist.at(5)
?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.
-
@bhargav
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
For example:
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!