Results 1 to 20 of 23

Thread: QString - Where is find_first_not_of?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QString - Where is find_first_not_of?

    Hello,

    1) Is there any QString function equivalent to
    Qt Code:
    1. std::string::find_first_of(const std::string & str, 0);
    To copy to clipboard, switch view to plain text mode 
    ?
    I want only 'true' or 'false' return value. I don't want position.

    2) Yes, I know there are QRegExp, but I want fastest solution.

    3) This is my code:
    Qt Code:
    1. bool find_first_not_of(const QString & chars, const QString & text)
    2. {
    3. //return true if text not contains any of char in chars
    4. QString::const_iterator it = text.constBegin();
    5. QString::const_iterator end = text.constEnd();
    6. while(it != end)
    7. {
    8. if(chars.contains(*it) == false)
    9. return true;
    10. ++it;
    11. }
    12.  
    13. return false;
    14. }
    To copy to clipboard, switch view to plain text mode 
    This is code with QRegExp:
    Qt Code:
    1. bool reg_find_first_not_of(const QString & chars, const QString & text)
    2. {
    3. const QRegExp r("[" + QRegExp::escape(chars) + "]+");
    4. return !r.exactMatch(text);
    5. }
    To copy to clipboard, switch view to plain text mode 
    Which code is faster?
    Last edited by lukass; 18th May 2011 at 21:04. Reason: fixed bugs in first and second function

Similar Threads

  1. Replies: 8
    Last Post: 25th November 2010, 11:40
  2. With QString create a QString&
    By avis_phoenix in forum Newbie
    Replies: 1
    Last Post: 21st April 2010, 22:05
  3. Replies: 4
    Last Post: 1st February 2010, 14:21
  4. Replies: 4
    Last Post: 31st January 2008, 20:44
  5. how to copy part of QString to anothe QString
    By nass in forum Qt Programming
    Replies: 1
    Last Post: 26th March 2007, 19:05

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.