Click here to Skip to main content
15,921,884 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have text "Привет" and i want convert it to Unicode
var str = "Привет";

 Encoding unicode = Encoding.Unicode;
 byte[] unicodeBytes = unicode.GetBytes(str);
 var rez = Encoding.UTF8.GetString(unicodeBytes).ToString();

In VS debugger i see this result

But in VS preview i see incorrect charset

Why so?

What I have tried:

I try convert it with Encoding, but its not work
Updated 15-Dec-17 8:22am
[no name] 15-Dec-17 14:08pm    
Your c# string is allready Unicode. See String Class (System)[^]
phil.o 15-Dec-17 14:16pm    
Exactly :) my virtual 5, you should put that as answer, as I cannot think of any other meaningful one.
[no name] 15-Dec-17 14:20pm    
Thank you very much. Ok I try to formulate an answer. Even These Unicode / Coding stuff holds a lot of traps for a None english like me :)
Perić Željko 17-Dec-17 9:03am    
Try UTF8 instead of Unicode , it works for Serbian latin and cyrilic fonts.

1 solution

c# strings are Unicode strings. It represents text as a sequence of UTF-16 code units.

Read e.g. this: String Class (System)[^]

Not a short read, but to understand unicode, you most probably Need to go through several articles liek this: Unicode and You – BetterExplained[^]

Please see also Still fighting with the terminologies of unicode vs. encoding - C# Discussion Boards[^]
Share this answer
PIEBALDconsult 16-Dec-17 12:05pm    
And also:
[no name] 16-Dec-17 12:09pm    
Yep. It is also the first link in the (on the second line) in the link I provided :-)

Both of them discuss this (in my opinion) minor thing like BOM, but do not go further into a close description for surrogates

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900