欧元符号的编码问题

欧元符号的编码问题

本文介绍了欧元符号的编码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行该代码时,它给我?而不是€(欧元符号)。
谁能告诉我该怎么做。

i have this code when i run it, it give me "?" instead of "€" (euro sign).Can anyone tell me what i can do to fix it.

    string Message = "Hello $ € £";
    Encoding iso = Encoding.GetEncoding("ISO-8859-1");
    Encoding utf8 = Encoding.UTF8;

    byte[] utfBytes = utf8.GetBytes(Message);
    byte[] isoBytes = Encoding.Convert(utf8, iso, utfBytes);
    string msg = iso.GetString(isoBytes);
    Console.WriteLine(msg);


推荐答案

string Message = "Hello $ € £";
Console.OutputEncoding = Encoding.UTF8;
Console.WriteLine(Message);

我刚刚确认了此功能,但是您还需要在控制台上使用正确的字体(例如我尝试了 Lucida Console,它还可以,此外,您还需要确保您的源代码(.cs文件或其他格式)采用utf8编码。

I just confirmed this works, but you also need to use the right font for your console (for example I tried "Lucida Console" which is OK. also, you also need to make sure your source code (.cs file or whatever) is in utf8 encoding.

这篇关于欧元符号的编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 05:56