Why is the output different between Console and Debug?
byte [] data = new byte [] {0xB1, 0x00,0xA6,0x7C, 0x4e, 0xEC, 0xE7, 0xFF, 0xDD, 0xCE};
Console.WriteLine (new String(Encoding.GetEncoding("ISO-8859-1").GetChars(data)));
Console.WriteLine (Encoding.UTF8.GetString(data));
Debug.WriteLine (new String(Encoding.GetEncoding("ISO-8859-1").GetChars(data)));
Debug.WriteLine (new String(Encoding.UTF8.GetChars(data)));
“Console.WriteLine” (Latin1 encoding) output -> ±¦|NìçÿÝÎ
“Console.WriteLine” (UTF8) output -> ��|N�����
“Debug.WriteLine” shows no output.
You have a
0x00in the second position of the array, which is, as you know, a string end.Debug.WriteLineoutputs in the ASCII encoding. Therefore, it outputs only the first byte in the Output window.If you change
0x00to0x01you will see the full output.MORE When I look at
new String(Encoding.GetEncoding("ISO-8859-1").GetChars(data))in the Watch window I see an exception being thrown:'new String(Encoding.GetEncoding("ISO-8859-1").GetChars(data))' threw an exception of type 'System.ArgumentException' string {System.ArgumentException}This usually happens when attempting to access an Array element that doesn’t exist.