streamreader ignores Ascii 144

G

Guest

I am reading in a file line by line using a stream reader. When it hits a
record that has the following character: É, it drops that position out of
the stream entirely. I beleive, according to asciitable.com, that the É is
an extended ascii character (144.) Does anyone know why the streamreader
drops this character from a line when it's reading it and if there is a
possible workaround?
 
H

Herfried K. Wagner [MVP]

mfm said:
I am reading in a file line by line using a stream reader. When it hits a
record that has the following character: É, it drops that position out of
the stream entirely. I beleive, according to asciitable.com, that the É
is
an extended ascii character (144.) Does anyone know why the streamreader
drops this character from a line when it's reading it and if there is a
possible workaround?

There is no ASCII code 144 because ASCII is a 7-bit encoding (character
codes 0 to 127). It's likely that the file has been saved using another
encoding. You can try to read the file by passing
'System.Text.Encoding.Default' (the current Windows ANSI codepage) to the
'StreamReader' object's constructor. Nevertheless, you need to know which
encoding has been used when saving the file in order to decode the file
correctly.
 
G

Guest

I am reading in a file line by line using a stream reader. When it
hits a record that has the following character: É, it drops that
position out of the stream entirely. I beleive, according to
asciitable.com, that the É is an extended ascii character (144.)
Does anyone know why the streamreader drops this character from a line
when it's reading it and if there is a possible workaround?


Try changing the stream's encoding type? Perhaps manually specify ASCII?
 
G

Guest

You're right, the ascii code is greater than 127, it's 144, an 'extended'
ascii code. Can you point me to a resource that talks more about how to set
the encoding type of the stream reader?
 
H

Herfried K. Wagner [MVP]

mfm said:
You're right, the ascii code is greater than 127, it's 144, an 'extended'
ascii code. Can you point me to a resource that talks more about how to
set
the encoding type of the stream reader?

It's as simple as 'Dim sr As New StreamReader(<path>, <encoding>)', where
'<encoding>' is the appropriate 'System.Text.Encoding'.
 

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