Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find Encoding for 1251 codepage

Tags:

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

like image 285
Captain Comic Avatar asked Oct 19 '10 11:10

Captain Comic


2 Answers

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"); 
like image 136
Michael Madsen Avatar answered Oct 14 '22 20:10

Michael Madsen


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

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); 
like image 31
razon Avatar answered Oct 14 '22 21:10

razon