0

I use the below code to convert from unicode to utf-8:

Encoding unicode = Encoding.Unicode;
Encoding UTF8 = Encoding.UTF8;
byte[] unicodeBytes = unicode.GetBytes(stringResp);
byte[] UTF8Bytes = Encoding.Convert(unicode, UTF8, unicodeBytes);
string stringResp = UTF8.GetString(UTF8Bytes, 0, UTF8Bytes.Length);

But the special characters doesn't show, only their unicode code (\u00c1 for Á for example). If I look manually the next string ("\\u00c1") and replace it for Á it works. Does someone knows why and how I can make an automatic conversion?

piet.t
  • 11,718
  • 21
  • 43
  • 52
  • 2
    `"\\u00c1"` is not a unicode code. Note the double backslash. You just escaped the backslash. That means, your string literally contains a backslash, followed by the characters '0','0','c','1'. `"\u00c1"` would be a code (assuming you are not using the `@""` verbatim string form). Not sure if that is just a typo in your question or whether the escaped backslash really appears in your source string, though... –  Jul 04 '18 at 17:00
  • If the string comes from the WebAPI with character sequences being Unicode escape sequences (instead of the actual Unicode characters themselves), you can look at this question and their answers for some tips of how to translate the string representation of `@"\uXXXX"` into an actual character: https://stackoverflow.com/questions/183907/how-do-i-convert-unicode-escape-sequences-to-unicode-characters-in-a-net-string –  Jul 04 '18 at 17:17
  • The scaped backlash, really appears in my source string. I will check it out your answer, thank you elgonzo. – Guillermo Gómez Sánchez Jul 04 '18 at 19:31

0 Answers0