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. Split hex encoded string

Split hex encoded string

Scheduled Pinned Locked Moved General and Desktop
qstringqstringlisthex formatregex
2 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.
  • A Offline
    A Offline
    azarubkin
    wrote on last edited by
    #1

    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
    0
    • C Offline
      C Offline
      Cedric
      wrote on last edited by
      #2

      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
      0

      • Login

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