How can I convert Cyrillic string into English in c#

前端 未结 10 962
醉酒成梦
醉酒成梦 2020-12-31 21:05

Is it posible to convert Cyrillic string to English(Latin) in c#? For example I need to convert \"Петролеум\" in \"Petroleum\". Plus I forgot to mention that if I have Cyril

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-31 21:57

    I'm not familiar with Cyrillic, but if it's just a 1-to-1 mapping of Cyrillic characters to Latin characters that you're after, you can use a dictionary of character pairs and map each character individually:

    var map = new Dictionary
    {
        { 'П', "P" },
        { 'е', "e" },
        { 'т', "t" },
        { 'р', "r" },
        ...
    }
    
    var result = string.Concat("Петролеум".Select(c => map[c]));
    

提交回复
热议问题