By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,264 Members | 1,753 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,264 IT Pros & Developers. It's quick & easy.

Decoding DOS formatted file

P: n/a
Hi all

In my C# program I need to read a file, which is exported from a DOS
program. So words such as "Afløser" (with special danish characters) is
read like "Afl�ser".

How do I decode/encode DOS formatted strings to the right ".net" format.

Cheers
Bjarne Nielsen
Aug 28 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Aug 28, 3:19 pm, Bjarne Nielsen <bniel...@post11.tele.dkwrote:
Hi all

In my C# program I need to read a file, which is exported from a DOS
program. So words such as "Aflser" (with special danish characters) is
read like "Afl?ser".

How do I decode/encode DOS formatted strings to the right ".net" format.

Cheers
Bjarne Nielsen
Hi,
try to take a look at the System.Text namespace. It contains classes
for encoding/decoding text
from/to different code pages. You should guess which encoding your
file uses (i.e. unicode, utf8, etc...)
and the uses the appropriate method of the encoding classes.

Ask if you need more help!
Bye.

Aug 28 '07 #2

P: n/a
On Aug 28, 2:19 pm, Bjarne Nielsen <bniel...@post11.tele.dkwrote:
In my C# program I need to read a file, which is exported from a DOS
program. So words such as "Aflser" (with special danish characters) is
read like "Afl?ser".

How do I decode/encode DOS formatted strings to the right ".net" format.
Find out which code page your file is in - it may be 437, but it may
not be - different systems used different code pages.

When you know the code page, use Encoding.GetEncoding(codePage) and
then supply that whatever method you're using to read the file.

Jon

Aug 28 '07 #3

P: n/a
On Tue, 28 Aug 2007 06:43:02 -0700, Jon Skeet [C# MVP] wrote:
On Aug 28, 2:19 pm, Bjarne Nielsen <bniel...@post11.tele.dkwrote:
>In my C# program I need to read a file, which is exported from a DOS
program. So words such as "Aflser" (with special danish characters) is
read like "Afl?ser".

How do I decode/encode DOS formatted strings to the right ".net" format.

Find out which code page your file is in - it may be 437, but it may
not be - different systems used different code pages.

When you know the code page, use Encoding.GetEncoding(codePage) and
then supply that whatever method you're using to read the file.

Jon
Thank you Jon and Ciccone

It took me quite some time to make it work, until I realised, that I needed
two different encodings, one for reading the file, and another for writing
back to the new file (it's a file conversion program).

But with your help and a lot of patience and fooling around, I got it to
work.

Thanks!
Aug 30 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.