Question

My application receives Integer Values for ISO 8859-1 Chars over TCP and should display it for testing in the console. For converting the Int/Bytes to ISO 8859-1 strings, I took the code from the accepted answer of this question:

var e = Encoding.GetEncoding("iso-8859-1");
var s = e.GetString(new byte[] { 189 });

Its working fine for example with a value of 189 which is ½ in ISO 8859-1. But in my test, I got a Byte with the value of 154 which is š (Latin small letter S with caron) according to this site.

The Problem is that it doesnt display it on the console, its just displays a Question mark like that: enter image description here and the Debugger shows only a plain string:enter image description here

What could be the error?

Any help will be greatly appreciated.

Was it helpful?

Solution

I'm going to go out on a limb here; ISO/IEC 8859-1 does not define values between 126 and 159. See http://en.wikipedia.org/wiki/ISO/IEC_8859-1

this works;

  var e = Encoding.GetEncoding("Windows-1252");
  var s = e.GetString(new byte[] { 154 });

  Console.OutputEncoding = Encoding.GetEncoding("Windows-1252");

  Console.WriteLine(s);

I believe Windows-1252 is prefered;

...however the draft HTML 5 specification requires that documents advertised as ISO-8859-1 actually be parsed with the Windows-1252 encoding.[2])

http://en.wikipedia.org/wiki/ISO/IEC_8859-1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top