Special Characters in StreamWriter with Encoding.ASCII C #

5

I am writing to a file via StreamWriter using Encoding.ASCII encoding. A situation appeared in which I need to write the letter "Ç". But if I try to do this, the file exits the "?" Character.

In this case, I need to use this encoding (I can not use UTF8). Is there any way I can handle this character and make it appear correctly in the file?

An excerpt from the code example:

StreamWriter streamArquivo = new StreamWriter(caminhoArquivo, false, Encoding.ASCII);
streamWriter.WriteLine("COBRANÇA");

I tried to see something related to the letter code "Ç" in byte, etc. but the problem continues. Is there any way to do this?

    
asked by anonymous 02.10.2015 / 14:22

1 answer

6

The simplest encoding that resolves your problem is Latin1 ( see table ). Instead of ASCII I would use:

Encoding.GetEncoding("iso-8859-1")

or

Encoding.GetEncoding(28591)

Depending on your case you may have to use the 850 or 860.

If you can not use it, the solution is to convert the text removing the accents . You have lost information, but it is the only solution left.

    
02.10.2015 / 15:32