1

Im wondering how I can display a Euro symbol in UTF-8 Format ?

Cheers

StevieB
  • 6,263
  • 38
  • 108
  • 193

2 Answers2

5

Euro symbol has unicode code U+20AC (decimal 8364) encoded in utf8 it translates to following bytes e2 82 ac

Ivan
  • 1,735
  • 1
  • 17
  • 26
  • Im sorry I do not understand your answer. So I need to replace € with "e2 82 ac" is it ? – StevieB May 31 '10 at 13:15
  • Nope, it's just a way it's binary coded in utf8 file. If you just need to output it you can just paste €. – Ivan Jun 01 '10 at 07:14
3

You can display it like this: €

Klaus Byskov Pedersen
  • 117,245
  • 29
  • 183
  • 222
  • The feedback I received was as follows after my symbol was indeed like the above in a XML file. "The euro symbol in this text is not encoded correctly and needs to be in UTF-8" What could be meant by that – StevieB May 31 '10 at 13:14
  • 1
    You need to make sure that the (unspecified) software you are using is saving the file in UTF-8 format and nothing is converting it to a different format along the way. – Quentin May 31 '10 at 13:17
  • In iso-8859-15, the € symbol is represented by `0xA4`, replacing a different character from iso-8859-1; in windows-1252, it's `0x80`. So the various single-byte encodings vary in their placement of this symbol - UTF-8 is simply safer. – Tim Pietzcker May 31 '10 at 13:18
  • Hey I am creating a XML in a project in Visual Studio using XmlTextWriter. I just noticed I have the following line of code Encoding utf8 = new UTF8Encoding(false); Should this be set to true ? – StevieB May 31 '10 at 13:21
  • Maybe I will make more sense like this to. Ok at the moment my euro symbol is displayed as € in my XML. After I somehow get UTF-8 encoding working how do it look like after ? – StevieB May 31 '10 at 13:24
  • Hey bobince. Thanks for your reply. But my XML Files are created dynamically ever 15 mins or so I need to do this "UTF-8 encoding of euro symbols" somehow dynamically. Can you suggest a way i can do this via my script ? I dont understand how € differs from € in UTF-8.. – StevieB May 31 '10 at 13:40
  • @StevieB: no, `new UTF8Encoding(false)` is fine. `true` would add a UTF-8-encoded faux-BOM, which in general you don't want. If you are talking about writing `€` in an XML file, just write `€` in the file in a text editor and use ‘Save as’ to save it in the UTF-8 encoding. If you're editing in Visual Studio, I believe the encoding is in File->Advanced Save Options. It totally sucks that Windows tools still default to some useless system default codepage instead of UTF-8. – bobince May 31 '10 at 13:40
  • 1
    You should understand what encodings are. The canonical link at this point would be [Spolsky's](http://www.joelonsoftware.com/articles/Unicode.html). How are you creating these files? Where are you writing a `€`? Does it come from code? What does the code look like? – bobince May 31 '10 at 13:43
  • In Visual Studio do I need to select UTF-8 with or without signature – StevieB May 31 '10 at 13:44
  • The files are created from a .NET script. Im writing the € in out of the elements of the XML File. The value € is pulled from the database, which was entered in the first play via CMS. Code looks i.e sample something like this XMLwriter.WriteElementString("Prim_Status", reader_image["Prim_Status"].ToString()); – StevieB May 31 '10 at 13:46
  • You could just use unicode escape sequence in your strings (\u20AC for euro). In example: Console.WriteLine("I need \u20AC") would output I need € – Ivan Jun 01 '10 at 22:25