Solved How to reverse a QByteArray
-
Hi! I have this code:
QByteArray a = "Test Data"; QByteArray aBase64 = a.toBase64(); qDebug() << aBase64;Upon executon, I get this: VGVzdCBEYXRh. How to reverse the resulting code?
-
Hi,
Are you thinking about QByteArray::fromBase64 ?
-
I want to get the resulting code written backwards: hRXY....
-
QByteArray a = "Test Data"; QByteArray aBase64 = a.toBase64(); QByteArray b(aBase64.size(),0); std::copy(aBase64.crbegin(),aBase64.crend(),b.begin()); qDebug() << aBase64; qDebug() << b;
-
@VRonin Thank you!
-
@VRonin class QByteArray' has no member named 'crbegin
-
@Hollywood33 that method was added ~2 years ago: http://doc.qt.io/qt-5/qbytearray.html#crbegin
What version of Qt are you using?
Workaround:
QByteArray a = "Test Data"; QByteArray aBase64 = a.toBase64(); QByteArray b; b.reserve(aBase64.size()); for(int i= aBase64.size()-1;i>=0;--i) b.append(aBase64.at(i)); qDebug() << aBase64; qDebug() << b;
-
@VRonin This works! Thanks!