Results 1 to 6 of 6

Thread: FindOneOf equalant in Qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up FindOneOf equalant in Qt

    Hi all,

    I need replacement for FindOneOf(charSet) function of CString in QString,

    This function Searches the string for the first character that matches any character contained in charSet and will return its position,

    Eg:

    CString s( "abcdef" );
    s.FindOneOf( "sd" );

    this will return 3 because d is the first matching character that is in 3rd Position.


    If anybody knows please help me?
    Thanks,
    Rajesh.S

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

    Default Re: FindOneOf equalant in Qt

    Qt Code:
    1. QString str = "abcdef";
    2. int i = str.indexOf(QRegExp("[sd]"));
    To copy to clipboard, switch view to plain text mode 

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

    rajeshs (3rd December 2007)

  4. #3
    Join Date
    Jan 2006
    Posts
    371
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: FindOneOf equalant in Qt

    Quote Originally Posted by wysota View Post
    Qt Code:
    1. QString str = "abcdef";
    2. int i = str.indexOf(QRegExp("[sd]"));
    To copy to clipboard, switch view to plain text mode 
    dud, don't you think this costs too much...? I think iterating over the string and using QString::indexOf(QChar) will be cheaper.

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

    Default Re: FindOneOf equalant in Qt

    I don't think so, but you may perform some tests to find out. Using your method you have a complexity of O(n*m) where n is the length of string and m is the number of characters you want to test against. I don't think a regular expresion will do worse. It might not be better for such a simple case, but shouldn't be worse. The more complex the expression, the better performance it gives over simple string comparison.

  6. #5
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: FindOneOf equalant in Qt

    using indexof() we can pass only character,

    For my need regular expression is needed,

    Thank you for your reply, and suggestions,

    Now i got clear picture.
    Thanks,
    Rajesh.S

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: FindOneOf equalant in Qt

    Quote Originally Posted by rajeshs View Post
    using indexof() we can pass only character,

    For my need regular expression is needed,
    Not quite. You can call indexOf multiple times with different characters and obtain the same result as with using a regular expression.

Similar Threads

  1. FindOneOf equalant in Qt
    By rajeshs in forum Qt Programming
    Replies: 2
    Last Post: 3rd December 2007, 11:59

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.