Results 1 to 2 of 2

Thread: QString::replace() with QRegExp capture modification

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

    Default QString::replace() with QRegExp capture modification

    Hi,

    I want to capitalize all letters in an <b> tag (and remove the tag):

    Qt Code:
    1. QRegExp rx("\\<b\\>(.*)\\</b\\>");
    2. rx.setMinimal(true);
    3. str.replace(rx, QString("\\1").toUpper());
    To copy to clipboard, switch view to plain text mode 

    but '\\1' is unfortunately replaced after the toUpper()
    So, how can I achieve to upper case the letters in a tag?



    Thanks,

    Lykurg

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

    Default Re: QString::replace() with QRegExp capture modification

    Qt Code:
    1. QRegExp rx("....");
    2. rx.setMinimal(true);
    3. int s = -1;
    4. while((s = rx.indexIn(str, s+1))>=0){
    5. str.replace(s, rx.cap(0).length(), rx.cap(1).toUpper());
    6. s+= rx.cap(1).length();
    7. }
    To copy to clipboard, switch view to plain text mode 

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

    Lykurg (4th March 2008)

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.