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

  • 本文关键字:马拉地 转换 英语 c#
  • 更新时间 :
  • 英文 :


我正在用 C# 开发一个 Windows 应用程序,为此我需要将英语数值转换为马拉地语数值。例如。"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)在这里不是一个选项,因为我们不想改变马拉地语数字

最新更新