Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QString count replacements
Qt 6.11 is out! See what's new in the release blog

QString count replacements

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 944 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • VolebabV Offline
    VolebabV Offline
    Volebab
    wrote on last edited by
    #1

    Is there a way to use QString::replace with QRegularExpression and count how many times it has replaced strings?
    For example, imagine that I have a string with: xaxbxc, and I want to replace "x" with "-", is there a way to know how many times `QRegularExpression' replaced? In this case it would return "3".

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      hi
      QString str = "banana and panama";
      str.count(QRegularExpression("a[nm]a")); // returns 4

      http://doc.qt.io/qt-5/qstring.html#count-5

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved