开发者

How to find Encoding for 1251 codepage

I need to create System.Encoding for 1251 codepage.

On m开发者_StackOverflow社区y russian Windows I use

Encoding encoding = Encoding.Default

I am afraid this will produce different results depending on Windows


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");


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

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);


The .NET Framework/.NET Core supports a large number of character encodings and code pages. To retrieve an encoding that is present in the .NET Framework/.NET Core pass the EncodingProvider object to the Encoding.RegisterProvider method to make the encodings supplied by the EncodingProvider object available to the common language runtime. Microsoft Document Reference

System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜