StreamReader won't read pound-sign

  • Thread starter Thread starter Per Rasmussen
  • Start date Start date
P

Per Rasmussen

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.
 
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
 
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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top