How do you convert a byte array to a string? I need to get the raw content, e.g. “96=A8=FC-=A8=FE”, but when I use say Encoding.UTF8.GetString(bytes), it returns “96��-��”. Thanks!
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think you misunderstand the content of strings. The closest you’ll get to “raw content” is to use
Encoding.Unicode– .NET uses UTF-16 internally, so converting to UTF-16 is effectively just a case of copying the contents of memory from the string to the byte array.Now, to come back to your problem, what data do you have, what is it meant to represent and why? Textual data is characters. Binary data is numbers, basically. You have to have a mapping between the two, and that’s the encoding.
I have an article on Unicode which may help you, but I strongly suspect you’ll need to take a step back before you make any progress.
If you’re trying to convert a byte array into a string representation of those bytes as hex, you can just use
BitConverter.ToString(byte[])but I wouldn’t describe that as a “raw” conversion.EDIT: Okay, now that we have the context, it’s much easier to answer. What you’re looking at is quoted printable encoding. The email should specify the encoding of the quoted printable, so when you decode the QP encoding, that’s what you should use. If you’re not currently storing the content encoding of the original email, you should start doing so right now…