繁体   English   中英

如何在C#中将英语中的数值转换为Marathi数值?

[英]How to convert numeric value in English to Marathi numeric value in C#?

我正在用C#开发Windows应用程序,为此我需要将英语数值转换为Marathi数值。 例如。 “ 123” =“ १२३”

最简单的方法是使用String.Replace方法并编写帮助程序类。

public class MarathiHelper
{
    private static Dictionary<char, char> arabicToMarathi = new Dictionary<char, char>()
    {
      {'1','१'},
      {'2','२'},
      {'3','३'},
      {'4','४'},
      {'5','५'},
      {'6','६'},
      {'7','७'},
      {'8','८'},
      {'9','९'},
      {'0','०'},
    };

    public static string ReplaceNumbers(string input)
    {
        foreach (var num in arabicToMarathi)
        {
            input = input.Replace(num.Key, num.Value);
        }
        return input;
    }

}

在您的代码中,您可以像这样使用它:

var marathi = MarathiHelper.ReplaceNumbers("123");

marathi将带有"१२३"

好吧,为了转换['0'..'9']每个字符,都应移位0x0966 - '0' 实现可能是

  string source = "The number is 0123456789";

  string result = new String(source
    .Select(c => c >= '0' && c <= '9' ? (Char) (c - '0' + 0x0966) : c)
    .ToArray()); 

结果( result )是

  The number is ०१२३४५६७८९

请注意, Char.IsDigit(c)不是选项,因为我们不想移动Marathi数字

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM