我怎么能转换西里尔字符串成英文在C# [英] How can I convert Cyrillic string into English in c#

查看:209
本文介绍了我怎么能转换西里尔字符串成英文在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它是更多钞票到西里尔文字符串在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?

推荐答案

我不熟悉的西里尔字母,但如果它只是一个西里尔字母到你以后拉丁字符1对1的映射,您可以使用字符对的字典和一个个字符分别映射:

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]));

这篇关于我怎么能转换西里尔字符串成英文在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆