Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Split hex encoded string

    General and Desktop
    qstring qstringlist hex format regex
    2
    2
    1262
    Loading More Posts
    • 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.
    • A
      azarubkin last edited by

      How do I split hex encoded string into substrings of 2 characters?
      Example: "806982" -> "80", "69", "82".

      I tried:

      QString s = "806982";
      QRegExp re("[\\da-fA-F]{2}"); // exactly 2 hex digits
      QStringList l = s.split(re);
      

      but it did not work as intended.

      1 Reply Last reply Reply Quote 0
      • C
        Cedric last edited by

        You can use a regular expression in a loop:

        QString s = "806982";
        QRegExp re("([\\da-fA-F]{2})"); // exactly 2 hex digits
        QStringList l;
        
        int pos = 0;
        
        while ((pos = re.indexIn(s, pos)) != -1) {
            l << re.cap(1);
            pos += re.matchedLength();
        }
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post