0

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);
rjmunro
  • 27,203
  • 20
  • 110
  • 132
Raheel
  • 595
  • 8
  • 21

3 Answers3

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.

enter image description here

agou
  • 728
  • 1
  • 10
  • 24
1

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)

Hans Kesting
  • 38,117
  • 9
  • 79
  • 111
0

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

Nilam Doctor
  • 491
  • 7
  • 18