Reading å, ä, ö from file with StreamReader
-
Hi. I’m unfourtunately in this case from Sweden which have the letters å, ä, ö. When I read lines in a textfile using StreamReader I got a “?” symbol when I print these letters. Any idea what to do… _____________________________ ...and justice for all APe
-
Hi. I’m unfourtunately in this case from Sweden which have the letters å, ä, ö. When I read lines in a textfile using StreamReader I got a “?” symbol when I print these letters. Any idea what to do… _____________________________ ...and justice for all APe
You'll have to give the encoding of the file when constructing the StreamReader. Regards, mav
-
Hi. I’m unfourtunately in this case from Sweden which have the letters å, ä, ö. When I read lines in a textfile using StreamReader I got a “?” symbol when I print these letters. Any idea what to do… _____________________________ ...and justice for all APe
-
You'll have to give the encoding of the file when constructing the StreamReader. Regards, mav
Any Idea of which Encoding I should use. I've tried the regular once. _____________________________ ...and justice for all APe
-
Any Idea of which Encoding I should use. I've tried the regular once. _____________________________ ...and justice for all APe
Depends on the encoding that was used to create the file. You can try Encoding.Default for a start (which is _not_ the same as not specifying an encoding, strangely enough). Regards, mav
-
Font file... Sorry I don't understand how I should use that... _____________________________ ...and justice for all APe
-
Depends on the encoding that was used to create the file. You can try Encoding.Default for a start (which is _not_ the same as not specifying an encoding, strangely enough). Regards, mav
Noppe. I've gone through ASCII, Unicode, Default, snd some more. Can there be something else that is wrong with my language settings of my CPU? I've shecked that an it is "Swedish". _____________________________ ...and justice for all APe
-
Hi. I’m unfourtunately in this case from Sweden which have the letters å, ä, ö. When I read lines in a textfile using StreamReader I got a “?” symbol when I print these letters. Any idea what to do… _____________________________ ...and justice for all APe
May sound stupid, but: Does the font you are using for display have those characters? If you are using a different encoding, you should get wrong characters, not just question-marks. Lets say you have a file with ÄäÖö in it. With a wrong encoding, you should get something like JWpM, since there are different chars there. With a wrong font, you will get like "Box","Box","Box","Box" or ????. Windows sees that there is no character in the font for the keycode given and then prints its "standard"-missing-char-in-font symbol. Try different "standard" fonts (those who come with windows), like "Arial Unicode", "Times", "Verdana", "Arial" ... Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.
-
May sound stupid, but: Does the font you are using for display have those characters? If you are using a different encoding, you should get wrong characters, not just question-marks. Lets say you have a file with ÄäÖö in it. With a wrong encoding, you should get something like JWpM, since there are different chars there. With a wrong font, you will get like "Box","Box","Box","Box" or ????. Windows sees that there is no character in the font for the keycode given and then prints its "standard"-missing-char-in-font symbol. Try different "standard" fonts (those who come with windows), like "Arial Unicode", "Times", "Verdana", "Arial" ... Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.
The file is only a simple txt-file written in Notepad. I'm writing the text back to a txt-file and eaven to the Console and error appears there too. I've tried The UTF8Encoding and then the , å, ä, ö doesn't appear at all. _____________________________ ...and justice for all APe
-
Hi. I’m unfourtunately in this case from Sweden which have the letters å, ä, ö. When I read lines in a textfile using StreamReader I got a “?” symbol when I print these letters. Any idea what to do… _____________________________ ...and justice for all APe
Hi, If the file was created on a windows system it is likely that it uses windows encoding. Try the windows-1252 encoding. This works for german pretty well... /cadi 24 hours is not enough
-
Hi. I’m unfourtunately in this case from Sweden which have the letters å, ä, ö. When I read lines in a textfile using StreamReader I got a “?” symbol when I print these letters. Any idea what to do… _____________________________ ...and justice for all APe
You need to know which encoding was used for these letters. It will probably be Windows-1252[^]. The default for StreamReader is UTF-8. Check a binary view of the file (you can use the arrow to the right of the Open button in VS, select Open With..., then choose Binary Editor) to see what the values of those characters are. If it's 1252, å should be 0xE5 (229), ä should be 0xE4 (228) and ö should be 0xF6 (246). However, it could conceivably be an old DOS/OEM codepage, in which case it's likely to be either 437[^] or 850[^]. In both of these, å = 0x86 (134), ä = 0x84 (132), and ö = 0x94 (148). If it's something more obscure you may be able to find it at FileFormat.Info[^]. Input the Unicode value of the characters (the hex values I've given for 1252). When you've worked out what code page you're dealing with, use the following:
StreamReader sr =
new StreamReader(
file,
System.Text.Encoding.GetEncoding(1252)
);Replace 1252 with the correct code page number. Stability. What an interesting concept. -- Chris Maunder
-
You need to know which encoding was used for these letters. It will probably be Windows-1252[^]. The default for StreamReader is UTF-8. Check a binary view of the file (you can use the arrow to the right of the Open button in VS, select Open With..., then choose Binary Editor) to see what the values of those characters are. If it's 1252, å should be 0xE5 (229), ä should be 0xE4 (228) and ö should be 0xF6 (246). However, it could conceivably be an old DOS/OEM codepage, in which case it's likely to be either 437[^] or 850[^]. In both of these, å = 0x86 (134), ä = 0x84 (132), and ö = 0x94 (148). If it's something more obscure you may be able to find it at FileFormat.Info[^]. Input the Unicode value of the characters (the hex values I've given for 1252). When you've worked out what code page you're dealing with, use the following:
StreamReader sr =
new StreamReader(
file,
System.Text.Encoding.GetEncoding(1252)
);Replace 1252 with the correct code page number. Stability. What an interesting concept. -- Chris Maunder
Thank You Mike Dimmick and cadi! You made it for me, and my week is saved. I'll bring up a skoal to you tomorrow evening. _____________________________ ...and justice for all APe