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
Forum Updated to NodeBB v4.3 + New Features

Split hex encoded string

Scheduled Pinned Locked Moved General and Desktop
qstringqstringlisthex formatregex
2 Posts 2 Posters 1.5k 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.
  • A Offline
    A Offline
    azarubkin
    wrote on 4 Dec 2015, 14:06 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 4 Dec 2015, 16:06 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

      1/2

      4 Dec 2015, 14:06

      • Login

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