How to find Encoding for 1251 codepage

2019-02-16 05:52发布

问题:

I need to create System.Encoding for 1251 codepage.

On my russian Windows I use

Encoding encoding = Encoding.Default

I am afraid this will produce different results depending on Windows

回答1:

Correct, you will get different results on different machines if you use Encoding.Default.

If you want a specific codepage, you can use Encoding.GetEncoding:

Encoding encoding = Encoding.GetEncoding("windows-1251");


回答2:

For .NET Core you also need to reference the System.Text.Encoding.CodePages package and then use Encoding.RegisterProvider:

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);


标签: c# .net encoding