Why doesn't my c# code recognize copyright symbol?

c#, unicode, utf-8

Solution

UTF8 requires multiple bytes to encode character points greater than 127. If you run the reverse, you'll see what it expects:

System.Text.Encoding.UTF8.GetBytes("©"); // { 194, 169 }

Try this:

byte[] newBytes = new Byte[] { 194, 169 };
string string1 = System.Text.Encoding.UTF8.GetString(newBytes, 0, newBytes.Length);

If you absolutely have to use that original byte array, you'll need to pick a different encoding. For example, the Windows-1252 encoding uses a single byte to encode the copyright symbol:

byte[] newBytes = new Byte[] { 169 };
var encoding = Encoding.GetEncoding(1252);
string string1 = encoding.GetString(newBytes, 0, newBytes.Length); // "©"

Problem

``` byte[] newBytes = new Byte[] { 169 }; string string1 = System.Text.Encoding.UTF8.GetString(newBytes, 0, newBytes.Length); ``` In the above program, I expected string1 to have the value of copyright symbol ©. But I get some other value (possibly some junk) as shown below Where did I go wrong?

Original source

Related problems