Encoding issue of Euro sign

梦想的初衷 提交于 2020-01-06 06:44:53

问题


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);

回答1:


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

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.




回答2:


Please refer to the URL http://www.cs.tut.fi/~jkorpela/html/euro.html it shows all methods for encoding.




回答3:


The euro sign is not a part of the ISO-8859-1 character set: http://en.wikipedia.org/wiki/ISO/IEC_8859-1#Codepage_layout (the pound sign does appear there)



来源:https://stackoverflow.com/questions/13373925/encoding-issue-of-euro-sign

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!