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. [solved] QRegExp to add spaces every 2nd character ?

[solved] QRegExp to add spaces every 2nd character ?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.5k Views
  • 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.
  • D Offline
    D Offline
    deleted28
    wrote on last edited by
    #1

    How the QRegExp should be designed ...

    @ QString pacA = "CC0D00FF6F00A8C0FFFFFFFF0000";
    qDebug() << pacA;
    QString pacB = pacA.replace(QRegExp("."), " " );
    qDebug() << pacB;@

    ... to get: "CC 0D 00 FF 6F 00 A8 C0 FF FF FF FF 00 00"

    pacA is created by reading a QByteArray filled with Byte data from QSerialPort.
    Maybe there's a possibility to add the space directly when reading the QByteArray ?

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

      Hi and welcome to devnet,

      @QString pacB = pacA.replace(QRegExp("([A-Z0-9]{2})"), "\1 " ).simplified();@

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        deleted28
        wrote on last edited by
        #3

        Great, thank you !

        I tried pretty much the same 27 times, always slightly different.
        Still analyzing what i did bad. I think the parenthesis made me mad

        :)

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome !

          You have a little regexp tool in Qt's example that helps write/test QRegExp.

          Now that it's working, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • D Offline
            D Offline
            deleted28
            wrote on last edited by
            #5

            I found and tested the example. Nice tool.
            Attaching a screenshot here is only possible if i have
            a place to make it available on the web, right ?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Currently, yes, but that might change in the future (following the thread of our new community manager)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

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