Problems using Enconding.UTF8.GetString(byte[]), values above 127 == ""

  • Thread starter Thread starter PrettySneaky
  • Start date Start date
P

PrettySneaky

Like the subject said. I have an byte array and want to save them in a
text file with UTF8 encoding. However when an element in the byte array
is above 127 the GetString method ignores the value and I get an
incorrect string.

Anyone who knows what the problem is?
 
Like the subject said. I have an byte array and want to save them in a
text file with UTF8 encoding. However when an element in the byte array
is above 127 the GetString method ignores the value and I get an
incorrect string.

Anyone who knows what the problem is?

Yes - you're trying to treat arbitrary binary data as if it were a
valid UTF8 string, which it's not. To save binary data in a text file,
you're best to use something like Base64. See Convert.ToBase64String
and Convert.FromBase64String.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top