Hello everyone, I am writing a simple parser for the exchange rate. in C #. instead of some of the meanings that he substitutes in Russian "?". I think this is because of UTF-16. http://www.cbr.ru/scripts/XML_daily.asp - link to data.
Asked
Active
Viewed 51 times
-1
-
2[When asking a question about a problem with code, people who are volunteering to help need the text of the code. Images of the code are not an acceptable substitute.](https://idownvotedbecau.se/imageofcode) – Liam May 27 '21 at 12:52
-
The problem is probably that the font lacks glyphs for the characters you are trying to print. See question about [console & unicode](https://stackoverflow.com/questions/388490/how-to-use-unicode-characters-in-windows-command-line) – JonasH May 27 '21 at 12:53
1 Answers
1
@ ŤỖŤỖŘŘỖ.
For using webclient to download Russian code (utf16) and output correctly in the console, you could use the following code:
static void Main(string[] args)
{
WebClient wc = new WebClient();
wc.Encoding = Encoding.UTF8;
byte[] code = wc.DownloadData("http://www.cbr.ru/scripts/XML_daily.asp");
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Encoding encoding1251 = Encoding.GetEncoding("windows-1251");
var convertedBytes = Encoding.Convert(encoding1251, Encoding.UTF8, code);
string result = Encoding.UTF8.GetString(convertedBytes);
Console.WriteLine(result);
}

Hui Liu-MSFT
- 770
- 4
- 15