How to convert UTF8 data to a ASCII data?

H

Hooyoo

I read the content from a file encoded with UTF8 like this:
byte[] data = binaryReader.ReadBytes(file.Length);

And next step, I want to transform data to ASCII format, How can I do
this?
You know, Using Encoding.UTF8.GetString(data) can get a ASCII string,
but I need a byte[].
I hope you get my point. Any suggestion will be appreciated.
 
A

Arthur

try

using System.Text;

ASCIIEncoding ascii = new ASCIIEncoding();
UTF8Encoding utf8 = new UTF8Encoding();

byte[] asciiBytes = Encoding.Convert(utf8, ascii, utf8bytes);
 

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

Top