Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert Cyrillic string into English in c#

Tags:

string

c#

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 Cyrillic string it need to stay like that, so can I somehow check that?

like image 596
Pece Avatar asked Jun 20 '10 13:06

Pece


3 Answers

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<char, string>
{
    { 'П', "P" },
    { 'е', "e" },
    { 'т', "t" },
    { 'р', "r" },
    ...
}

var result = string.Concat("Петролеум".Select(c => map[c]));
like image 77
dtb Avatar answered Oct 14 '22 21:10

dtb


You can of course map the letters to the latin transcription, but you won't get an english word out of it in most cases. E.g. Российская Федерация transcribes to Rossiyskaya Federatsiya. wikipedia offers an overview of the mapping. You are probably looking for a translation service, google probably offers an api for that.

like image 40
Femaref Avatar answered Oct 14 '22 20:10

Femaref


If you're using Windows 7, you can take advantage of the new ELS (Extended Linguistic Services) API, which provides transliteration functionality for you. Have a look at the Windows 7 API Code Pack - it's a set of managed wrappers on top of many new API in Windows 7 (such as the new Taskbar). Look in the Samples folder for the Transliterator example, you'll find it's exactly what you're looking for:

like image 33
Igal Tabachnik Avatar answered Oct 14 '22 20:10

Igal Tabachnik