Results 1 to 7 of 7

Thread: extract contents in double quote from a qstring

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: extract contents in double quote from a qstring

    Or QRegExp in Qt4.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    May 2008
    Location
    Tripoli Libya
    Posts
    70
    Thanks
    10
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: extract contents in double quote from a qstring

    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QtCore>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. //case double qoute delimeter
    7. QString test("\"apple\" \"orange\" \"fig\"");
    8. QStringList splits=test.split("\" \"",QString::SkipEmptyParts);
    9. foreach(QString s,splits)
    10. qDebug()<< s;
    11.  
    12. //using Regexp
    13. QString v=" Abcd(efhj:xyz; abc:\" hello\"; pqr:\"hi\")";
    14. QRegExp rx("\"([^\"]*)\"");
    15. int pos = 0;
    16. while ((pos = rx.indexIn(v, pos)) != -1)
    17. {
    18. list << rx.cap(0);
    19. pos += rx.matchedLength();
    20. }
    21. //qDebug()<<list;
    22. foreach(QString str,list)
    23. qDebug()<<str;
    24.  
    25.  
    26. QCoreApplication a(argc, argv);
    27.  
    28. return a.exec();
    29. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to alrawab for this useful post:

    decipher (27th February 2013)

Similar Threads

  1. Replies: 4
    Last Post: 21st June 2011, 12:05
  2. Replies: 8
    Last Post: 17th June 2011, 00:35
  3. Insertion double quote into string/qstring
    By MarkoSan in forum General Programming
    Replies: 12
    Last Post: 14th December 2007, 12:23
  4. double to QString
    By swiety in forum Qt Programming
    Replies: 2
    Last Post: 22nd November 2007, 14:11
  5. qt ready fn to extract ip address from a qstring
    By nass in forum Qt Programming
    Replies: 3
    Last Post: 26th March 2007, 15:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.