Read and convert CP437 text file

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
 
J

Jon Skeet [C# MVP]

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));
 
G

Gustaf Liljegren

Jon Skeet said:
When you create the StreamReader, use:

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

So easy. Thanks a lot!

Gustaf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top