é writing out from a streamreader??

J

Jason Gleason

I'm having a problem with the streamreader class. When i read out of a file,
characters like é are taken out when i do readline. Why does this happen?
When i switch the encoding to ascii, it replaces those characters with a
question mark. How do i get them to read correctly from a file? So the
character é is correctly read into the .net program?
 
B

Bret Mulvey [MS]

Jason Gleason said:
I'm having a problem with the streamreader class. When i read out of a file,
characters like é are taken out when i do readline. Why does this happen?
When i switch the encoding to ascii, it replaces those characters with a
question mark. How do i get them to read correctly from a file? So the
character é is correctly read into the .net program?

When the characters where stored in the stream, a specific text encoding was
used to translate the characters into a sequence of bytes. You need to know
what encoding that was in order to read the stream properly. ASCII won't
work because é isn't in the ASCII character set.

Try other encodings such as UTF8, iso-8859-1, etc. To get an Encoding object
for iso-8859-1, use Encoding.GetEncoding("iso-8859-1") and pass this to the
StreamReader constructor.
 

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

Top