views:

168

answers:

1

I'm writing a stream to a file and stdout, but I'm getting some kind of encoding like this:

\u05ea\u05e7\u05dc\u05d9\u05d8 \u05e9\u05e1\u05d9\u05de\u05dc \u05e9\u05d9\u05e0\u05d5\u05d9 \u05d1\u05e1\u05d2\u05e0\u05d5\u05df \u05dc\u05d3\u05e2\u05ea\u05d9 \u05d0\u05dd \u05d0\u05e0\u05d9 \u05d6\u05d5\u05db\u05e8 \u05e0\u05db\u05d5\u05df

How can I convert this to a printable string?

+3  A: 

I can't figure out how you are printing the string, but that is just Unicode:

#include <QString>
#include <QFile>
#include <QDebug>

int main(int argc, char **argv)
{

  QString s = "\u05ea\u05e7\u05dc\u05d9\u05d8 \u05e9\u05e1\u05d9\u05de\u05dc \u05e9\u05d9\u05e0\u05d5\u05d9 \u05d1\u05e1\u05d2\u05e0\u05d5\u05df \u05dc\u05d3\u05e2\u05ea\u05d9 \u05d0\u05dd \u05d0\u05e0\u05d9 \u05d6\u05d5\u05db\u05e8 \u05e0\u05db\u05d5\u05df";

  QFile file1("1.txt");
  if (!file1.open(QIODevice::WriteOnly | QIODevice::Text))
    return 1;

  QTextStream out(&file1);
  out << s << "\n";

  qDebug() << s;
  return 0;
}

If I compile and run it

g++ -lQtCore -I /usr/include/QtCore test.cpp 
./a.out 

I can see the printable characters both in the console debug output and in the file:

"תקליט שסימל שינוי בסגנון לדעתי אם אני זוכר נכון" 

So you are probably doing something wrong or looking in the wrong direction, can you paste your code so we can help you better?

duncan
That's not UTF-8. `\uXXXX` is a *Unicode escape sequence*: a textual representation of a Unicode code point.
Alan Moore
Thanks, You are right. Those are Unicode based characters. AFAIK there is no UTF-8 escape sequences because UTF-8 is just a way to write/encode Unicode equivalent characters.The resulting file is encoded in UTF-8:$ file 1.txt 1.txt: UTF-8 Unicode text
duncan