473,490 Members | 2,592 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 8483
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
10454
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
7719
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
2225
by: Naren | last post by:
Hello All, Can any one help me in this file read problem. #include <stdio.h> int main() {
10
2519
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
5205
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
7515
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
18952
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
411
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
6114
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...
0
7112
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7146
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7183
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4573
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.