我试图强制我的表单使用阿拉伯格式,例如将(1-2-3-4-..等)数字显示为(٠、١、٢、٣、٤、٥、٦ 、 ٧ 、 ٨ 、 ٩) 在我的所有形式中,无论它是Textbox
,orlables
或者无论它是什么
我搜索并发现了很多关于这个问题的问题,其中大多数都不起作用,而我认为其他的似乎不是很好的答案,例如此处接受的答案 https://stackoverflow.com/questions/2298153/how-can-i-convert-english-digits-to-arabic-digits如下所示,我在表单加载方面尝试过,这对我的问题没有影响
这是一个接受的答案 https://stackoverflow.com/questions/8926792/converting-numbers-from-western-arabic-digits-1-2-3-to-eastern-arabic-digit那说文化信息不会有帮助,是吗?因为我认为这个答案不对
所以请有人能帮助我
private void F0102_Load(object sender, EventArgs e)
{
CultureInfo ar_culture = new CultureInfo("ar-SA");
Thread.CurrentThread.CurrentCulture = ar_culture;
Thread.CurrentThread.CurrentUICulture = ar_culture;
}
大多数阿拉伯人使用西方阿拉伯数字(1、2、3...)进行数学计算。因此,即使ar-SA
你在格式化数字时得到的文化。使用您自己的格式化函数来获取东部阿拉伯数字。
public static string ToArabic(long num)
{
const string _arabicDigits = "۰۱۲۳۴۵۶۷۸۹";
return new string(num.ToString().Select(c => _arabicDigits[c - '0']).ToArray());
}
您还可以创建自己的格式提供程序:
public class ArabicNumberFormatProvider : IFormatProvider, ICustomFormatter
{
public static readonly ArabicNumberFormatProvider Instance =
new ArabicNumberFormatProvider();
private ArabicNumberFormatProvider() { }
public object GetFormat(Type formatType) { return this; }
public string Format(string format, object arg, IFormatProvider formatProvider)
{
switch (arg) {
case long l:
return ToArabic(l);
case int i:
return ToArabic(i);
default:
return null;
}
}
public static string ToArabic(long num)
{
const string _arabicDigits = "۰۱۲۳۴۵۶۷۸۹";
return new string(num.ToString().Select(c => _arabicDigits[c - '0']).ToArray());
}
}
Example:
string arabic = String.Format(ArabicNumberFormatProvider.Instance,"{0}", 1234567890);
Output:
1234567890
然而,num.ToString(ArabicNumberFormatProvider.Instance)
不起作用。看https://stackoverflow.com/a/6240052/880990 https://stackoverflow.com/a/6240052/880990了解详情。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)