• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-1
Question by tanuj0092 · May 26, 2014 at 11:22 AM · serverstringcharacterslanguageencoding

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!!!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Multiaki · Dec 06, 2015 at 04:05 AM 0
Share

Could you solve the problem?

avatar image kidmosey · Dec 06, 2015 at 08:52 AM 0
Share

Try Encoding.Unicode ins$$anonymous$$d of Encoding.UTF8

2 Replies

· Add your reply
  • Sort: 
avatar image
1

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Dec 10, 2015 at 05:36 PM 1
Share

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.

avatar image Multiaki Bunny83 · Dec 10, 2015 at 05:45 PM 0
Share

Thanks, Fixed

avatar image
0

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Dec 10, 2015 at 05:02 AM 0
Share

@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.

avatar image tanuj0092 · Dec 10, 2015 at 05:41 PM 0
Share

@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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

C#, SmartFox, which 3D MMORPG authoritative server? 0 Answers

PlayerPrefs not storing string? 0 Answers

Unity networking tutorial? 6 Answers

Scandinavian letters 'Æ', 'Ø' and 'Å' 2 Answers

count characters in string 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges