encoding of textfile
-
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.
-
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.
perhaps unicode?
-
perhaps unicode?
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 :^)
-
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 :^)
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:).
-
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.
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.