How can i convert Utf-8 encoding to normal text
-
Let me try one more time
I am converting Bengali letters into** Utf-8 encoding** and i am storing the **converted Utf-8 encoding of Bengali letters in to a file **and, i want to read the data present in the file i.e i want to the Utf-8 encoded text from file and i want to convert encoding i.e Utf-8 encoded data into bengali letters and then i want to display the Bengali data that came from Utf-8 encoding that was present in file.
-
@Rohith said:
convert encoding i.e Utf-8 encoded data into bengali letters
the question is what encoding do you expect for the "bengali letters"?!
Since the bengali characters can already be stored using UTF-8 encoding!Still u didn't tell me where you have problems displaying it...
-
@raven-worx
Here I am trying to convert Bengali Unicode to Bengali text and print that.
Bengali Unicode is present in file, and I am trying to read that Unicode from file and convert it to original Bengali textThis is Original Bengali Text :- "সবাইকে শুভ সকাল"
The unicode reading from file :- \u09b8\u09ac\u09be\u0987\u0995\u09c7 \u09b6\u09c1\u09ad \u09b8\u0995\u09be\u09b2O/P to be shown after reading unicode from file :- সবাইকে শুভ সকাল
We are getting problem that whenever we are trying to read unicode from file dynamically and convert to original text.
As we are passing unicode Text statically its working fine.
-
@Rohith said:
The unicode reading from file :- \u09b8\u09ac\u09be\u0987\u0995\u09c7 \u09b6\u09c1\u09ad \u09b8\u0995\u09be\u09b2
You mean this is the content of the file as text-representation?
Can you please upload an example file? -
Yeah that is what i mean
\u09b8\u09ac\u09be\u0987\u0995\u09c7 \u09b6\u09c1\u09ad \u09b8\u0995\u09be\u09b2
save this content in to a .txt file and try to read the content form the file and present it as normal text
here i am not getting how to upload file in this forum
-
@Rohith
finally we get together, since this is an important info.
You then have to "parse" the text data to the desired unicode representation.QString str = ...; // read from the file int idx = -1; while ( ( idx = str.indexOf("\\u") ) != -1 ) { int uc = str.mid(idx+2, 4).toInt(0,16); str.replace(idx, 6, QChar(uc)); }
The reason it worked "statically" for you was, that the compiler already did the correct interpretation for you during compilation.
-
Thanks it worked....!
-
@Rohith
just to clarify:
To transfer this information this way is rather resource wasteful.
Since you create for 1 Unicode character 6 ASCII characters. This means (roughly - not exact) a factor of 6. Additionally you have to do the parsing.If possible i would change it, so the unicode text is transfered as "RAW" unicode in binary format.
-
-
@Rohith
instead of converting the unicode string to the escaped characters send it directly in binary form. When you have a QString already you can callQString::toUtf8()
and send the returned QByteArray directly. On the client its enough to doQString::fromUtf8( receivedUtf8ByteArray.constData() )
It depends how you implemented the transfer.
But theoretically it should be enough to replace your unicode escaping code on the server with this approach.