obsidian-execute-code icon indicating copy to clipboard operation
obsidian-execute-code copied to clipboard

C# encoding problems

Open Mideks opened this issue 3 years ago • 7 comments

When I try to output something in C# with Console.WriteLine() in Cyrillic, I get incomprehensible characters instead of what I actually wrote. However, when I enter data with Console.ReadLine() and then output it, it's fine. I don't think this is the behavior one would expect

Below I present a code snippet that demonstrates this: image

Mideks avatar Feb 12 '23 09:02 Mideks

Interesting, thanks! What OS are you using? What is its primary configured language?

chlohal avatar Feb 13 '23 15:02 chlohal

My operating system is Windows 10 and the main language in the system is Russian. By the way, in other languages the encoding is fine (JS, Python): image image

Mideks avatar Feb 14 '23 03:02 Mideks

Could you try putting this snippet before your code?

Console.OutputEncoding = System.Text.Encoding.UTF8;

chlohal avatar Feb 14 '23 16:02 chlohal

Huh, the problem is reversed image

Mideks avatar Feb 15 '23 14:02 Mideks

Okay, I added an encoding for the output, and now it works properly image

Mideks avatar Feb 15 '23 14:02 Mideks

I pasted these two lines into the settings in the C# language settings in the plugin and now it works as expected! image

Thanks for the help.

Mideks avatar Feb 15 '23 14:02 Mideks

I think the problem is related to #200. Windows still uses windows-1252 as the default encoding. The injected code changes this to utf-8 which makes it work. I think we will just add the settings you use as default settings in the next release.

twibiral avatar Feb 23 '23 23:02 twibiral