Results 1 to 7 of 7

Thread: extract contents in double quote from a qstring

  1. #1
    Join Date
    May 2012
    Posts
    33
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default extract contents in double quote from a qstring

    I have a string like

    Abcd(efhj:xyz; abc:” hello”; pqr:“hi”)

    how do i extract only hello and hi from the above string
    please guide
    thanks

  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


  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: extract contents in double quote from a qstring

    Use QRegularExpression to match quoted words. This way you get to captured text which would be hello and hi.

  4. #4
    Join Date
    May 2012
    Posts
    33
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: extract contents in double quote from a qstring

    thanks both of you..its still not working
    changing the delimiterpattern to
    Qt Code:
    1. QString delimiterPattern("” ”")
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. QString delimiterPattern(" " " ")
    To copy to clipboard, switch view to plain text mode 

    didn't work

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: extract contents in double quote from a qstring

    Of course not. Do not just copy and past. Try to understand what the code is actually doing. Instead of split I would focus on QRegularExpression.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.


  7. #7
    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 

  8. 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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.