【问题标题】:.Net Core 欧元货币符号未显示在 RegionInfo 中
【发布时间】:2022-01-23 15:49:37
【问题描述】:

我不知道这可能是 .net 问题还是我需要配置的东西。使用控制台应用在 NET 5 和 6 中测试。 有什么想法吗?

using System;
using System.Globalization;

public class Example
{
    public static void Main()
    {
        CultureInfo culture1 = CultureInfo.CurrentCulture;
        Console.WriteLine("The current culture is {0} -> {1}", culture1.Name, culture1.DisplayName);
        CultureInfo uiCulture2 = CultureInfo.CurrentUICulture;
        Console.WriteLine("The current UI culture is {0} -> {1}\n", uiCulture2.Name, culture1.DisplayName);

        Console.WriteLine();

        RegionInfo myRI1 = new RegionInfo("ES");
        Console.WriteLine("   Name:                         {0}", myRI1.Name);
        Console.WriteLine("   DisplayName:                  {0}", myRI1.DisplayName);
        Console.WriteLine("   EnglishName:                  {0}", myRI1.EnglishName);
        Console.WriteLine("   IsMetric:                     {0}", myRI1.IsMetric);
        Console.WriteLine("   ThreeLetterISORegionName:     {0}", myRI1.ThreeLetterISORegionName);
        Console.WriteLine("   ThreeLetterWindowsRegionName: {0}", myRI1.ThreeLetterWindowsRegionName);
        Console.WriteLine("   TwoLetterISORegionName:       {0}", myRI1.TwoLetterISORegionName);
        Console.WriteLine("   CurrencySymbol:               {0}", myRI1.CurrencySymbol);
        Console.WriteLine("   ISOCurrencySymbol:            {0}", myRI1.ISOCurrencySymbol);

        Console.ReadLine();
    }
}

返回:

Name:                         ES
DisplayName:                  España
EnglishName:                  Spain
IsMetric:                     True
ThreeLetterISORegionName:     ESP
ThreeLetterWindowsRegionName: ESP
TwoLetterISORegionName:       ES
CurrencySymbol:               ?    <= should be €
ISOCurrencySymbol:            EUR

在装有 Win11 和 Win10 的计算机上执行。 其他地区如 GB、US、PK 工作正常。

【问题讨论】:

  • 欧元符号没有任何问题。如果有的话,自 2001 年以来,数以百万计的开发人员和用户会注意到。区域信息数据直接来自 Windows。如果存在这样的问题,欧洲的所有用户都会注意到。你在哪里显示这个输出?你确定这不是字体或控制台问题吗?
  • 尝试在 Windows 终端中运行您的代码。如果您使用旧控制台,请确保在控制台属性中启用Unicode
  • 看看字符串转储:用string.Join(" ", myRI1.CurrencySymbol.Select(c =&gt; $"{c} (\\u{(int)c:x4})"))代替myRI1.CurrencySymbol。现在您有了每个字符的代码,例如€ (\u20ac)。如果你有正确的代码和错误的字符,你应该责怪字体

标签: c# .net culture


【解决方案1】:

没写完:

Console.OutputEncoding = System.Text.Encoding.UTF8;

感谢@Panagiotis Kanavos

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-17
    • 2013-10-26
    • 1970-01-01
    • 2015-07-10
    • 2019-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多