Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. encoding of textfile

encoding of textfile

Scheduled Pinned Locked Moved C#
tutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stephan_007
    wrote on last edited by
    #1

    hy everyone! does anyone of you know how to get the correct encoding of a textfile? because i do read the file via a streamreader and write a new one with streamwriter. but sometimes i do have problems with some signs. i know the file was created on a unix machine (line seperators just \n instead of \r\n in windows etc.). streamreader and streamwriter allow encoding to be used as a second/additional parameter when reading or writing of/to the file. so my two questions: 1) which encoding do i have to use for unix textfiles so the characters are read and written correctly? (because here in europe we have characters like "ö" or "ä" but they are not displayed correctly during writing the file. in the original file they are displayed correctly. so i want to provide the encoding in the parameter, but there are so many. and i am not sure, if i choose one which seems to be working on one file, does this mean it works for every unix textfile? 2) is there a chance to get the encoding of the file, when reading it without knowing it from the beginning? meaning, i want to find out the encoding when i access the file and set it when reading it, some kind of "dynamic encoding setting". thanks. stephan.

    D L 2 Replies Last reply
    0
    • S stephan_007

      hy everyone! does anyone of you know how to get the correct encoding of a textfile? because i do read the file via a streamreader and write a new one with streamwriter. but sometimes i do have problems with some signs. i know the file was created on a unix machine (line seperators just \n instead of \r\n in windows etc.). streamreader and streamwriter allow encoding to be used as a second/additional parameter when reading or writing of/to the file. so my two questions: 1) which encoding do i have to use for unix textfiles so the characters are read and written correctly? (because here in europe we have characters like "ö" or "ä" but they are not displayed correctly during writing the file. in the original file they are displayed correctly. so i want to provide the encoding in the parameter, but there are so many. and i am not sure, if i choose one which seems to be working on one file, does this mean it works for every unix textfile? 2) is there a chance to get the encoding of the file, when reading it without knowing it from the beginning? meaning, i want to find out the encoding when i access the file and set it when reading it, some kind of "dynamic encoding setting". thanks. stephan.

      D Offline
      D Offline
      Derek Bartram
      wrote on last edited by
      #2

      perhaps unicode?

      S 1 Reply Last reply
      0
      • D Derek Bartram

        perhaps unicode?

        S Offline
        S Offline
        stephan_007
        wrote on last edited by
        #3

        and which encoding type do i have to use? because i read the msdn but it confused me more than it helped. tons of different encoding specifications and descriptions :^)

        D 1 Reply Last reply
        0
        • S stephan_007

          and which encoding type do i have to use? because i read the msdn but it confused me more than it helped. tons of different encoding specifications and descriptions :^)

          D Offline
          D Offline
          Derek Bartram
          wrote on last edited by
          #4

          Sorry, I really don't know. Something unicode based is what you're looking for though I think. Personally I would say stop using *nix, but then i'm sure you have a good reason not too (otherwise i'll bash your head in with a really big book :mad:).

          1 Reply Last reply
          0
          • S stephan_007

            hy everyone! does anyone of you know how to get the correct encoding of a textfile? because i do read the file via a streamreader and write a new one with streamwriter. but sometimes i do have problems with some signs. i know the file was created on a unix machine (line seperators just \n instead of \r\n in windows etc.). streamreader and streamwriter allow encoding to be used as a second/additional parameter when reading or writing of/to the file. so my two questions: 1) which encoding do i have to use for unix textfiles so the characters are read and written correctly? (because here in europe we have characters like "ö" or "ä" but they are not displayed correctly during writing the file. in the original file they are displayed correctly. so i want to provide the encoding in the parameter, but there are so many. and i am not sure, if i choose one which seems to be working on one file, does this mean it works for every unix textfile? 2) is there a chance to get the encoding of the file, when reading it without knowing it from the beginning? meaning, i want to find out the encoding when i access the file and set it when reading it, some kind of "dynamic encoding setting". thanks. stephan.

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Hi, try new Encoding(codepage) where codepage probably is 1252. There is no general way of detecting the encoding; if it is Unicode/UTF8 you will find two special leading bytes; if it is an 8-bit ASCII extension (as I expect it is for you), you won't get a clue: every codepage is another way to map the top 128 byte values to a immense collection of possible characters. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups