Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. how to extract the date from string?
Forum Updated to NodeBB v4.3 + New Features

how to extract the date from string?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 3 Posters 2.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bhargav
    wrote on last edited by
    #1

    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.

    JonBJ S 2 Replies Last reply
    0
    • B bhargav

      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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @bhargav
      The way you've done it already, isn't it just list.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.

      B 1 Reply Last reply
      1
      • B bhargav

        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.

        S Offline
        S Offline
        Stoyan
        wrote on last edited by
        #3

        @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");
        
        B 1 Reply Last reply
        3
        • JonBJ JonB

          @bhargav
          The way you've done it already, isn't it just list.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.

          B Offline
          B Offline
          bhargav
          wrote on last edited by
          #4

          @JonB thanq for for ur solution.

          1 Reply Last reply
          0
          • S Stoyan

            @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");
            
            B Offline
            B Offline
            bhargav
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved