[英]How to convert numeric value in English to Marathi numeric value in C#?
I am developing an windows application in C#, for that I need to convert English numeric value to Marathi numeric value. 我正在用C#开发Windows应用程序,为此我需要将英语数值转换为Marathi数值。 For Example.
例如。 "123" = "१२३"
“ 123” =“ १२३”
The most obviose way is use String.Replace
method and write helper class. 最简单的方法是使用
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;
}
}
And in your code you can use it like this: 在您的代码中,您可以像这样使用它:
var marathi = MarathiHelper.ReplaceNumbers("123");
marathi
will have "१२३"
marathi
将带有"१२३"
Well, in order to convert every character in ['0'..'9']
should be shifted by 0x0966 - '0'
; 好吧,为了转换
['0'..'9']
每个字符,都应移位0x0966 - '0'
; and the implementation could be 实现可能是
string source = "The number is 0123456789";
string result = new String(source
.Select(c => c >= '0' && c <= '9' ? (Char) (c - '0' + 0x0966) : c)
.ToArray());
The outcome ( result
) is 结果(
result
)是
The number is ०१२३४५६७८९
Note, that Char.IsDigit(c)
is not an option here, since we don't want to shift Marathi numbers 请注意,
Char.IsDigit(c)
不是选项,因为我们不想移动Marathi数字
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.