C# russian cp1251 Encode/Decode

442 Views Asked by At

I'm using ASCII 1251 table for russian letters. So I need a C# function to convert char to 1251 decimal code and vise versa.

For example russian 'а' is 224, 219 is 'Ы'.

Are the any way not to use dictionary with hard-coded values for all the letters?

1

There are 1 best solutions below

3
Serg On BEST ANSWER

Just use Encoding class.

var enc = Encoding.GetEncoding(1251);
Console.WriteLine(enc.GetBytes("Ы")[0]); //will print 219
Console.WriteLine(enc.GetString(new byte []{219})); //will pring Ы