在 UWP 中将 int 转换为阿拉伯数字字符串



我正在尝试使用 String.Format 将整数转换为字符串,但我需要数字来反映具有经典形状的语言(如阿拉伯语和泰语(的当前文化。这在以前在 WPF 中是可能的,但 UWP 似乎缺少 DigitShapes(即使 System.Globalization.CultureInfo.CurrentCulture 仍然可用(。有人知道 UWP 中的解决方法吗?

我想我找到了解决方案。UWP 中支持 NumeralSystemTranslator 类。这并不像我希望的那么容易,但是如果您手动设置 NumeralSystemTranslator.NumeralSystem 属性(默认情况下是拉丁语(,它将返回您指定的区域设置的数字的本机字符。值列表在这里。

因此,对于阿拉伯语,您可以执行以下操作:

NumeralSystemTranslator translator = new NumeralSystemTranslator();
translator.NumeralSystem = "Arab";
string output = translator.TranslateNumerals("5");

我花了一段时间才找到这个。希望对其他人也有帮助:)

最新更新