473,387 Members | 1,528 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,387 software developers and data experts.

Decoding DOS formatted file

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
3 2487
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 "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
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
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 "Afløser" (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
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 "Afløser" (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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ding feng | last post by:
I have got formatted files. All of these file takes this form: obj1 method1 obj2 string1 obj3 string2 argument. Of course, each file can have maximum fields as shown above, or minimun fields...
6
by: mesterak | last post by:
I have some log files I need to process via VB.NET and C# based applications. I read the entire contents of each file individually into a string variable using the StreamReader class (.ReadToEnd). ...
5
by: ashishnh33 | last post by:
cud u plz tell me how to find all .obj files in the system using c++ culd u plz tell me the concept plzzzzz.
3
by: John | last post by:
I have a text file that is formatted like this: 123456789 SOLD 1 12/12/2006 Smith 45,525 987654321 SOLD 3 01/01/2006 Jones 23,252
5
by: Peter Jansson | last post by:
Hello group, The following code is an attempt to perform URL-decoding of URL-encoded string. Note that std::istringstream is used within the switch, within the loop. Three main issues have been...
1
by: lenniekuah | last post by:
I have written a VB6 program extracting Customers Name and address from a table to incorporate it into a letter and output it to MS WORDS. At the bottom of the letter I tried to insert a digitised...
6
by: redcic | last post by:
Hi all, I use the csv module of Python to write a file. My code is of the form : cw = csv.writer(open("out.txt", "wb")) cw.writerow() cw.writerow() And i get an out.txt file looking like:
2
by: ajay0419 | last post by:
Hi: I am trying to read from a file, which stores answers for a particular question(The answers are stop listed ). Each answer in the file is enclosed in opening and closing braces. Here is the...
10
by: Jun | last post by:
hello, I've a data file ======== 4 1 1 1 1 5 1 1 1 1 1 2 1 1 ========
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.