473,378 Members | 1,156 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Read and convert CP437 text file

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

Nov 15 '05 #1
2 8437
Gustaf Liljegren <gu**************@bredband.net> wrote:
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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote:
When you create the StreamReader, use:

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


So easy. Thanks a lot!

Gustaf
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Guyon Morée | last post by:
what is the difference? if I open a text file in binary (rb) mode, it doesn't matter... the read() output is the same.
3
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a...
7
by: Naren | last post by:
Hello All, Can any one help me in this file read problem. #include <stdio.h> int main() {
10
by: Tibby | last post by:
I need to read/write not only text files, but binary as well. It seems like on binary files, it doesn't right the last 10% of the file. -- Thanks --- Outgoing mail is certified Virus...
3
by: JenHu | last post by:
Hi, I want read line by line and characters. The characters are fix length text file, no specific delimited method between each fields. The first line is header line, the last line is footer. ...
5
by: JenHu | last post by:
Hi experts, I wrote a function which retrieves a file in the folder, the file path is : Dim sr As New StreamReader(strFilepath & ReturnFileName) What if I have more than 1 file_name in...
3
by: nicolasg | last post by:
Hi, I'm trying to open a file (any file) in binary mode and save it inside a new text file. After that I want to read the source from the text file and save it back to the disk with its...
0
by: Stephen Brown | last post by:
Yes indeed, pyExcelerator does support reading data from excel spreadsheets. An example of how to do this is included in the file xls2csv-gerry.py under the directory ......
2
by: Plumebee | last post by:
Hi, I am very new to programming and have just started to use Visual Basic 2005 Express Edition. I am trying to read from a text file to draw a rectangles and lines. However to begin I'm trying to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.