Punk1503
Punk1503

Reputation: 79

C# russian cp1251 Encode/Decode

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?

Upvotes: 1

Views: 713

Answers (1)

Serg
Serg

Reputation: 4696

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 Ы

Upvotes: 2

Related Questions