Read and convert CP437 text file

  • Thread starter Thread starter Gustaf Liljegren
  • Start date Start date
G

Gustaf Liljegren

I'm writing a console program that is supposed to read a bunch of old text
files written in CP437 encoding, extract parts of them and output
well-formed XML in UTF-8. First problem I run into is to make the conversion
from this antique codepage to UTF-8. The input file is read using the
StreamReader:

StreamReader file = new StreamReader(args[0]);

The output file is written using the XmlTextWriter:

XmlTextWriter writer = new XmlTextWriter("output.xml", Encoding.UTF8);

The result now, as expected, is that non-ASCII characters are skipped in the
output. What's the best way to make the conversion from CP437?

Thanks,

Gustaf
 
Gustaf Liljegren said:
I'm writing a console program that is supposed to read a bunch of old text
files written in CP437 encoding, extract parts of them and output
well-formed XML in UTF-8. First problem I run into is to make the conversion
from this antique codepage to UTF-8. The input file is read using the
StreamReader:

StreamReader file = new StreamReader(args[0]);

The output file is written using the XmlTextWriter:

XmlTextWriter writer = new XmlTextWriter("output.xml", Encoding.UTF8);

The result now, as expected, is that non-ASCII characters are skipped in the
output. What's the best way to make the conversion from CP437?

When you create the StreamReader, use:

StreamReader file = new StreamReader (args[0],
Encoding.GetEncoding(437));
 
Jon Skeet said:
When you create the StreamReader, use:

StreamReader file = new StreamReader (args[0],
Encoding.GetEncoding(437));

So easy. Thanks a lot!

Gustaf
 
Back
Top