我怎样才能英语数字转换为阿拉伯数字? [英] How can i convert english digits to arabic digits?
本文介绍了我怎样才能英语数字转换为阿拉伯数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个C#code例如:
I have this C# code for example
DateTime.Now.ToString("MMMM dd, yyyy");
现在当前线程加载阿拉伯文化。所以结果是这样的。
Now the current thread is loading the Arabic culture. So the result is like this
???? 19, 2010
但我不希望'2010'和'19'是英文(又称拉丁或的西阿拉伯语位数) - 我想东阿拉伯数字,如2
But i don't want the '2010' and the '19' to be in English (also known as Latin or West Arabic digits) - I want East Arabic numbers like "٢".
我试过
DateTime.Now.ToString("MMMM dd, yyyy", CultureInfo.GetCultureInfo("ar-lb"));
,得到相同的结果。
因此,任何想法?
gave the same result. So any idea?
推荐答案
你的这种解决方法(只列出你想使用字符串数组在这个数字所有文化):
Thy this workaround (just list all cultures you want to use this numerals in the string array):
private static class ArabicNumeralHelper
{
public static string ConvertNumerals(this string input)
{
if (new string[] { "ar-lb", "ar-SA" }
.Contains(Thread.CurrentThread.CurrentCulture.Name))
{
return input.Replace('0', '\u06f0')
.Replace('1', '\u06f1')
.Replace('2', '\u06f2')
.Replace('3', '\u06f3')
.Replace('4', '\u06f4')
.Replace('5', '\u06f5')
.Replace('6', '\u06f6')
.Replace('7', '\u06f7')
.Replace('8', '\u06f8')
.Replace('9', '\u06f9');
}
else return input;
}
}
然后使用方法,为您的所有字符串
你想拥有中央阿拉伯数字中,像这样的:
Then use the method, for all of your strings
you want to have 'central Arabic numerals' in, like this:
DateTime.Now.ToString().ConvertNumerals();
这篇关于我怎样才能英语数字转换为阿拉伯数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文