How to transliterate Cyrillic to Latin text

后端 未结 10 1314
情话喂你
情话喂你 2020-12-05 05:01

I have a method which turns any Latin text (e.g. English, French, German, Polish) into its slug form,

e.g. Alpha Bravo Charlie => alpha-bravo-char

10条回答
  •  独厮守ぢ
    2020-12-05 05:38

    Use this method Just pass your Cyrillic word contain string and this method return Latin English string corresponding to Cyrillic string.

    public static string GetLatinCodeFromCyrillic(string str)
        {
    
            str = str.Replace("б", "b");
            str = str.Replace("Б", "B");
    
            str = str.Replace("в", "v");
            str = str.Replace("В", "V");
    
            str = str.Replace("г", "h");
            str = str.Replace("Г", "H");
    
            str = str.Replace("ґ", "g");
            str = str.Replace("Ґ", "G");
    
            str = str.Replace("д", "d");
            str = str.Replace("Д", "D");
    
            str = str.Replace("є", "ye");
            str = str.Replace("Э", "Ye");
    
            str = str.Replace("ж", "zh");
            str = str.Replace("Ж", "Zh");
    
            str = str.Replace("з", "z");
            str = str.Replace("З", "Z");
    
            str = str.Replace("и", "y");
            str = str.Replace("И", "Y");
    
            str = str.Replace("ї", "yi");
            str = str.Replace("Ї", "YI");
    
            str = str.Replace("й", "j");
            str = str.Replace("Й", "J");
    
            str = str.Replace("к", "k");
            str = str.Replace("К", "K");
    
            str = str.Replace("л", "l");
            str = str.Replace("Л", "L");
    
            str = str.Replace("м", "m");
            str = str.Replace("М", "M");
    
            str = str.Replace("н", "n");
            str = str.Replace("Н", "N");
    
            str = str.Replace("п", "p");
            str = str.Replace("П", "P");
    
            str = str.Replace("р", "r");
            str = str.Replace("Р", "R");
    
            str = str.Replace("с", "s");
            str = str.Replace("С", "S");
    
            str = str.Replace("ч", "ch");
            str = str.Replace("Ч", "CH");
    
            str = str.Replace("ш", "sh");
            str = str.Replace("Щ", "SHH");
    
            str = str.Replace("ю", "yu");
            str = str.Replace("Ю", "YU");
    
            str = str.Replace("Я", "YA");
            str = str.Replace("я", "ya");
    
            str = str.Replace('ь', '"');
            str = str.Replace("Ь", "");
    
            str = str.Replace('т', 't');
            str = str.Replace("Т", "T");
    
            str = str.Replace('ц', 'c');
            str = str.Replace("Ц", "C");
    
            str = str.Replace('о', 'o');
            str = str.Replace("О", "O");
    
            str = str.Replace('е', 'e');
            str = str.Replace("Е", "E");
    
            str = str.Replace('а', 'a');
            str = str.Replace("А", "A");
    
            str = str.Replace('ф', 'f');
            str = str.Replace("Ф", "F");
    
            str = str.Replace('і', 'i');
            str = str.Replace("І", "I");
    
            str = str.Replace('У', 'U');
            str = str.Replace("у", "u");
    
            str = str.Replace('х', 'x');
            str = str.Replace("Х", "X");
            return str;
        }
    

提交回复
热议问题