sql >> Databasteknik >  >> RDS >> Sqlserver

Kyrillisk kodning i C#

// To find out source and target
const string source = "Ðàáîòà â ãåðìàíèè";
const string destination = "Работа в германии";

foreach (var sourceEncoding in Encoding.GetEncodings())
{

    var bytes = sourceEncoding.GetEncoding().GetBytes(source);
    foreach (var targetEncoding in Encoding.GetEncodings())
    {
        if (targetEncoding.GetEncoding().GetString(bytes) == destination)
        {
            Console.WriteLine("Source Encoding: {0} TargetEncoding: {1}",sourceEncoding.CodePage,targetEncoding.CodePage);
        }

    }
}

// Result1: Source Encoding: 1252 TargetEncoding: 1251
// Result2: Source Encoding: 28591 TargetEncoding: 1251
// Result3: Source Encoding: 28605 TargetEncoding: 1251

// The code for you to use 
var decodedCyrillic = Encoding.GetEncoding(1251).GetString(Encoding.GetEncoding(1252).GetBytes(source));
// Result: Работа в германии


  1. Rensa indata till en kolumn i postgres

  2. Laravel kan inte ansluta till databasen - Migrationer - Fel 2002

  3. Fel under installationen - Databasinitiering misslyckades

  4. Hänvisar till ett kolumnalias i en WHERE-klausul