如何将英文数值转换为C#中的马拉地语数值?

时间:2016-01-28 07:39:35

标签: c#

我正在用C#开发一个Windows应用程序,因为我需要将英文数值转换为Marathi数值。例如。 “123”=“123”

2 个答案:

答案 0 :(得分:2)

最令人信服的方法是使用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"१२३"

答案 1 :(得分:2)

好吧,为了转换['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)不是一个选项,因为我们不想改变马拉地语数字

相关问题