I cannot apply Encoder to the text to correctly display "ç, accents, other special characters"

Asked

Viewed 963 times

0

Hello,

I need to gather some information from the station, and I’m getting it. However in the received text I cannot apply an Encoder to correctly display the special characters:

inserir a descrição da imagem aqui

I have tried using "ISO-8859-1", and other Ncode forms as well

string blah = System.Text.Encoding.Unicode.GetString(System.Text.Encoding.Unicode.GetBytes(suaString));

or

byte[] bytes = Encoding.Default.GetBytes(sOutput);
sOutput = Encoding.UTF8.GetString(bytes);
var teste = Encoding.UTF8.GetString(bytes);

2 answers

1

I made an application here and I circled on a Windows 10 machine in Portuguese and another with windows 10 in English, and on the two machines I got the same result.

When I just made the line below:

string sOutput = CurrentProcess.StandardOutput.ReadToEnd();

the encoding was correct, but when I ran

Encoding iso = Encoding.GetEncoding("us-ascii");
Encoding utf8 = Encoding.UTF8;
byte[] utfBytes = utf8.GetBytes(sOutput);
byte[] isoBytes = Encoding.Convert(utf8, iso, utfBytes);
sOutput = iso.GetString(isoBytes);

The same problem you’re having happened.

I mean, I don’t see the need for you to do the conversions.

  • Tiago S Failed, see: Hostname: CPU-434A Operating system name: Microsoft Windows 7 Professional Versæo operating system: 6.1.7601 Service Pack 1 compiles‡Æo 7601 Operating System Manufacturer: Microsoft Corporation Configures OS‡æo: This‡æo member work

  • This line string sOutput = CurrentProcess.StandardOutput.ReadToEnd(); returned that?

  • Yeah, it came back the way it did.

0


To get around the difficulty I took the characters that were coming and replaced them by the equivalent characters :

sOutput = sOutput.Replace('?', 'ç').Replace('Æ', 'ã').Replace('¢', 'ó').Replace('¡', 'í').Replace("Portuguçs","Português");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.