I apologize for the dumb questions. But I do not understand a damn thing in encodings. There is such a line: \ u041f \ u0440 \ u043e \ u0434 \ u0443 \ u043a \ u0442 \ u0434 \ u043e \ u0431 \ u0430 \ u0432 \ u043b \ u0435 \ u043d

How to convert it to normal Cyrillic?

Tried an example with MSDN - does not help. The string does not change at all.

  • one
    This line already contains Cyrillic. ideone.com/CuNAun - VladD
  • Well, or if your string actually contains not one character '\u041f' , but 6 characters '\\' , 'u' , '0' , '4' , '1' , 'f' , then you, instead of using JSON parser rip out the text from the JSON response with regulars. Just don't do it. - VladD
  • Thought there is a solution. But okay ... I will use newtonsoft. - Alexander Li

1 answer 1

An unexpectedly simple solution was found:

 var s = @"\u041f\u0440\u043e\u0434\u0443\u043a\u0442 " + @"\u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d"; var d = Regex.Unescape(s); // "Продукт добавлен" 

The root of the problem is that you do not have a Unicode string, but a string in which non-ASCII characters are encoded by escape sequences. That is, the problem is not in encodings, but in the contents of the string itself.

Most likely, you received such a string when trying to manually parse some high-level format (JSON?). It is best in such cases not to reinvent the wheel, but to trust the finished parser.

  • Usually I use ready-made parsers, But there is only one such operation. pull the whole libu is not reasonable. - Alexander Li