Decoding DOS formatted file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bjarne Nielsen

    #1

    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
  • ciccone1978@gmail.com

    #2
    Re: Decoding DOS formatted file

    On Aug 28, 3:19 pm, Bjarne Nielsen <bniel...@post1 1.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.

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Decoding DOS formatted file

      On Aug 28, 2:19 pm, Bjarne Nielsen <bniel...@post1 1.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.GetEnc oding(codePage) and
      then supply that whatever method you're using to read the file.

      Jon

      Comment

      • Bjarne Nielsen

        #4
        Re: Decoding DOS formatted file

        On Tue, 28 Aug 2007 06:43:02 -0700, Jon Skeet [C# MVP] wrote:
        On Aug 28, 2:19 pm, Bjarne Nielsen <bniel...@post1 1.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.GetEnc oding(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!

        Comment

        Working...