vb.net streamreader - Characters Above ASCII 127

  • Thread starter Thread starter pabelard
  • Start date Start date
P

pabelard

I am reading from a file and trying to find out if it has
characters above ASCII 127 in it. My sample file does
have several of these characters. However, the
streamreader seems to skip over them. Even if I read in
lines and then write them out to another file, the high
ASCII number characters disappear.

My code:


Dim strInChar As Integer
Dim srSourceFileReader As System.IO.StreamReader
srSourceFileReader = New StreamReader(FullPathName)

strInChar = srSourceFileReader.Peek
Do While srSourceFileReader.Peek() >= 0
If strInChar > 127 O
strLogMessage = "Bad ASCII Character: " & strInChar
Console.WriteLine(strLogMessage)
End If 'strInChar > 127
strInChar = srSourceFileReader.Read()
Loop ' srSourceFileReader.Peek() >= 0

srSourceFileReader.Close()
 
* "pabelard said:
I am reading from a file and trying to find out if it has
characters above ASCII 127 in it. My sample file does
have several of these characters. However, the
streamreader seems to skip over them. Even if I read in
lines and then write them out to another file, the high
ASCII number characters disappear.

Dim strInChar As Integer
Dim srSourceFileReader As System.IO.StreamReader
srSourceFileReader = New StreamReader(FullPathName)

This will read the file with UTF-8 encoding, AFAIK. Have a look at the
overloads for the streamreader's constructor. There is at least one
that lets you specify the encoding that should be used to read the
text. Maybe 'Encoding.Default' will help, but that depends on the
encoding that was used to save the file.
 
Is the source file Unicode?? All .NET functions are Unicode by default - I
think you should check the encoding used in your code.
_____________________________
The Grim Reaper
 
Hi Pabelard,

You can use
if Asc(strInchar) > 127
although it says asc it gives back the values above the 127 as well.

I hope this helps?

Cor
 
Back
Top