I have a problem converting a text file from ANSI to UTF8 in C #. I am trying to display the results in a browser.
So, I have this text file with a lot of accent characters. It is encoded in ANSI, so I have to convert it to utf8 because "?" Appears in the browser instead of accents. No matter how I tried to convert to UTF8, it was still a “?”. But if I convert a text file to notepad ++ in utf8, then the accent characters will be removed.
here is the world of coding code I made:
public string Encode(string text)
{
byte[] myASCIIBytes = ASCIIEncoding.ASCII.GetBytes(text);
byte[] myUTF8Bytes = ASCIIEncoding.Convert(ASCIIEncoding.ASCII, UTF8Encoding.UTF8, myASCIIBytes);
return UTF8Encoding.UTF8.GetString(myUTF8Bytes);
}
Do you have an idea why this is happening?
source
share