Which encoding to use for CMD script?

Asked

Viewed 701 times

0

Windows Command Prompt uses an ASCII table different from ours, which even I don’t know what it is.

So much so that a batch with special characters when printed on the screen looks weird: Opção de área de influência stays OpþÒo de ßrea de influÛncia.

To correct this, without sacrificing what will be displayed on the screen, a table is used to replace special characters by others that are unreadable but represent the character on the ASCII screen of the CMD.

Example: writing in batch Op‡Æo de  rea de influˆncia he printa on the screen Opção de área de influência as it should be.

I did not find an ASCII table pattern with these correspondents, so I have to compare one by one.

For ease I want to do a routine in C# that after the batch written it reads it and the special characters are replaced by the corresponding ones. The problem is that the output replaces the special characters with ?. I suppose that’s coding problem.

I want to know which encoding to use to read the file and to save the changes to the new.

The switch I built:

switch (Letra)
{
    case 'á': return ' ';
    case 'à': return '…';
    case 'ã': return 'Æ';
    case 'ä': return '„';
    case 'â': return 'ƒ';
    case 'Á': return 'µ';
    case 'À': return '·';
    case 'Ã': return 'Ç';
    case 'Ä': return 'Ž';
    case 'Â': return '¶';
    case 'é': return '‚';
    case 'è': return 'Š';
    case 'ë': return '‰';
    case 'ê': return 'ˆ';
    case 'É': return '';
    case 'È': return 'Ô';
    case 'Ë': return 'Ó';
    case 'Ê': return 'Ò';
    case 'í': return '¡';
    case 'ì': return '';
    case 'ï': return '‹';
    case 'î': return 'Œ';
    case 'Í': return 'Ö';
    case 'Ì': return 'Þ';
    case 'Ï': return 'Ø';
    case 'Î': return '×';
    case 'ó': return '¢';
    case 'ò': return '•';
    case 'õ': return 'ä';
    case 'ö': return '”';
    case 'ô': return '“';
    case 'Ó': return 'à';
    case 'Ò': return 'ã';
    case 'Õ': return 'å';
    case 'Ö': return '™';
    case 'Ô': return 'â';
    case 'ú': return '£';
    case 'ù': return '—';
    case 'ü': return '';
    case 'û': return '–';
    case 'Ú': return 'é';
    case 'Ù': return 'ë';
    case 'Ü': return 'š';
    case 'Û': return 'ê';
    case 'ç': return '‡';
    case 'Ç': return '€';
    default: return Letra;
}
  • "Windows Command Prompt uses an ASCII table other than ours, which even I don’t know what it is." In fact ASCII is equal in qq place. What changes is ASCII Extended, with code pages that depend on OS configuration. Your switch will have a problem because it will only work for one of the numerous existing code pages.

  • For us here, the most common ones are 850 and 437, but this varies a lot. https://en.wikipedia.org/wiki/Code_page_850

  • Another tip: When using this type of conversion, do not put the character typed in the editor, use its code, otherwise the source code is very tied to the editor in use. And it can be problematic to open the source in utf-8, for example. PS: I imagine that C# already has something ready to do these conversions.

  • You do not have to do this trick.. rsrs.. see here: http://answall.com/a/105648/4793

No answers

Browser other questions tagged

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