如何将英文数字转换为阿拉伯数字? [英] How can i convert English digits to Arabic digits?
本文介绍了如何将英文数字转换为阿拉伯数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如我有这个 C# 代码
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' 是英文的(也称为拉丁文或 西阿拉伯语 数字) - 我想要像٢"这样的东阿拉伯数字.
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屋!
查看全文