Results 1 to 4 of 4

Thread: QString - find and replace text

  1. #1
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QString - find and replace text

    Hi!
    Imagine i want to replace all occurrences of "textA" by "textB" in "str".
    (QString str, textA, textB; )
    Is there a function for this or i must create a loop and replace until no more occurrences found?

    Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QString - find and replace text

    Take a look at QString::replace() docs and read what it does.
    J-P Nurmi

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QString - find and replace text

    Didnt you have a look at QString::replace ??

  4. #4
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QString - find and replace text

    Yeap ... missed that one.
    Thanks

    PS: Promisse i will look carefully before posting nest time

    QString & QString::replace ( const QString & before, const QString & after, Qt::CaseSensitivity cs = Qt::CaseSensitive )

    This is an overloaded member function, provided for convenience.

    Replaces every occurrence of the string before with the string after.

    If cs is Qt::CaseSensitive (the default), the search is case sensitive; otherwise the search is case insensitive.

    Example:

    QString str = "colour behaviour flavour neighbour";
    str.replace(QString("ou"), QString("o"));
    // str == "color behavior flavor neighbor"

    Note: The replacement text is not rescanned after it is inserted.

    Example:

    QString equis = "xxxxxx";
    equis.replace("xx", "x");
    // equis == "xxx"

Similar Threads

  1. Custom Model Advice Requested
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 16:26
  2. char* to QString. Segfault after delete []
    By TheRonin in forum Qt Programming
    Replies: 9
    Last Post: 19th June 2008, 13:20
  3. easiest Way QString can do
    By baray98 in forum Qt Programming
    Replies: 12
    Last Post: 15th April 2008, 20:49
  4. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 20:47
  5. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.