469,632 Members | 1,730 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,632 developers. It's quick & easy.

StreamReader won't read pound-sign

When I use a StreamReader to read lines from a file, it seems to skip some
"special" characters like ?, ć, ř and ĺ. How do I prevent it from doing
this? I know it works if the text file is in unicode but unfortunately this
is not a possibility for me in this case because I do not save the text
files myself and there are way too many to do manuel convertion.

Thanks in advance,
Per Rasmussen.
Sep 7 '06 #1
2 4569
Hi,

Per Rasmussen napisał(a):
When I use a StreamReader to read lines from a file, it seems to skip some
"special" characters like ?, ć, ř and ĺ. How do I prevent it from doing
this? I know it works if the text file is in unicode but unfortunately this
is not a possibility for me in this case because I do not save the text
files myself and there are way too many to do manuel convertion.

Thanks in advance,
Per Rasmussen.
You will need to set right encoding in a StreamReader
constructor or set the encoding detection.
I don't know what a code page you'll have to work with?
If you don't know that encoding you'll need to consider
of raw-byte reader-converter.

With regards
Marcin
Sep 7 '06 #2
Hi Per,

As Marcin said, the encoding is wrong. The default encoding for a
StreamReader is UTF8, but most likely you are reading something written
with ANSI encoding.

Try
StreamReader sr = new StreamReader(filename, Encoding.Default);
On Thu, 07 Sep 2006 11:00:57 +0200, Per Rasmussen <p@p.pwrote:
When I use a StreamReader to read lines from a file, it seems to skip
some
"special" characters like ?, ć, ř and ĺ. How do I prevent it from doing
this? I know it works if the text file is in unicode but unfortunately
this
is not a possibility for me in this case because I do not save the text
files myself and there are way too many to do manuel convertion.

Thanks in advance,
Per Rasmussen.



--
Happy Coding!
Morten Wennevik [C# MVP]
Sep 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jason Gleason | last post: by
3 posts views Thread by Rene | last post: by
4 posts views Thread by Astronomically Confused | last post: by
21 posts views Thread by JoKur | last post: by
6 posts views Thread by Jesper | last post: by
1 post views Thread by Pantelis Sotiropoulos | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.