Results 1 to 4 of 4

Thread: QString::indexOf Qt::CaseInsensitive

  1. #1
    Join Date
    May 2009
    Posts
    52
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default QString::indexOf Qt::CaseInsensitive

    Hello,

    Ca anyone explain me if indexOf() is bugged or has a meaning I don't really understand?

    For example

    Qt Code:
    1. QString str = "Splash Screen";
    2. QString pattern = "SCreen";
    3.  
    4. int i = str.indexOf(pattern, Qt::CaseInsensitive);
    5. cout << i << endl;
    To copy to clipboard, switch view to plain text mode 

    will print -1, I say it should print 7

    On the other hand contains() works ok

    bool b = str.contains(pattern, Qt::CaseInsensitive);
    cout << b << endl;
    this will return TRUE

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QString::indexOf Qt::CaseInsensitive

    QString::indexOf() takes case-sensitivity as its 3rd argument, the 2nd is the start-offset to start the search...

    HTH

  3. The following 4 users say thank you to caduel for this useful post:

    azalea (6th February 2024), Carlsberg (19th May 2009), chel[myaso] (7th February 2013), wladek (8th February 2011)

  4. #3
    Join Date
    May 2009
    Posts
    52
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QString::indexOf Qt::CaseInsensitive

    lol. I'm going now to check my eyes

  5. #4
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QString::indexOf Qt::CaseInsensitive

    I think that even with correct indexOf call it should return you -1.

    You have
    Qt Code:
    1. QString str = "Splash Screen";
    2. QString pattern = "SCreen";
    To copy to clipboard, switch view to plain text mode 

    and obviously "SCreen" is not a part of "SplashScreen".
    I'm a rebel in the S.D.G.

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.