- Home /
How can I convert UTF8 string to arabic?
Actually my game contains arabic language. I get the string "\u0639\u0632\u0648\u0632 \u0627\u0646\u062f\u062c\u0627\u0646\u064a" from server. I need to convert it into arabic. I am using this code:
byte[] _data = System.Text.Encoding.ASCII.GetBytes( Target );
string _temp = System.Text.Encoding.UTF8.GetString ( _data );
byte[] _data1 = System.Text.Encoding.UTF8.GetBytes ( _temp );
return System.Text.Encoding.ASCII.GetString ( _data1 );
where target is the string received from server. Please help!!!
Answer by Multiaki · Dec 10, 2015 at 05:23 PM
Here is the solution I found online. It worked for me. http://stackoverflow.com/questions/1615559/converting-unicode-strings-to-escaped-ascii-string
static string DecodeEncodedNonAsciiCharacters( string value ) {
return Regex.Replace(
value,
@"\\u(?<Value>[a-fA-F0-9]{4})",
m => {
return ((char) int.Parse( m.Groups["Value"].Value, NumberStyles.HexNumber )).ToString();
} );
}
Hope it helps!
Aki
Uhm, that's the same link i posted in my answer...
Also make sure you read the comment below that answer on StackOverflow. The regular expression should be @"\\u(?<Value>[a-fA-F0-9]{4})"
since only hex characters are allowed.
Answer by Bunny83 · Dec 06, 2015 at 12:41 PM
You actually shouldn't do anything with encoding since the encoding classes are only responsible for character to byte and byte to character conversion. What you have in your string is just an "escaped" string.
You have to unescape it manually, that's all. Uri.UnescapeDataString is said to work as well.
@tanuj0092:
Uhm, why did you downvote my answer? Any reason? If your string literally contains such escaped sequences you need to unescape them to get unicode characters. If your actual string contains unicode you don't have to do anything since C# supports unicode characters. As long as you use a font that supports your characters everything should be fine.
By downvoting without a comment / reason you won't get friends here... I did not downvote your question, you can check my activity log.
@Bunny83: Hey man! I didn't purposefully. I realized it late when nothing can be undone! I do know you didn't down vote this question.
Regarding the question, I was able to achieve it by simple stringify algorithm.
Your answer
Follow this Question
Related Questions
Scandinavian letters 'Æ', 'Ø' and 'Å' 2 Answers
Unity networking tutorial? 6 Answers
Split a string every 'n' characters? 5 Answers
Cyrillic characters displays as question marks. 0 Answers
Disabling google analytics 2 Answers