Anton
Anton

Reputation: 126

How can I convert QByteArray to QString with separator '-'?

I'm new in Qt and can't find any solution in Qt libraries.
I'd like to find smth without loop usage.
Is there any way to convert QByteArray to QString with - between bytes?
For example:

QByteArray = XX1F2C5A
QString = "XX-1F-2C-5A".

Upvotes: 1

Views: 1056

Answers (1)

spinkus
spinkus

Reputation: 8560

Yeah you can with QString::replace:

  QByteArray b = "XX1F2C5A";
  QString s(b);
  qDebug() << s;
  s.replace(QRegExp("(..)[^$]"), QString("\\1-"));
  qDebug() << s;

Upvotes: 2

Related Questions