vb.net streamreader - Characters Above ASCII 127

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()
 
H

Herfried K. Wagner [MVP]

* "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.
 
T

The Grim Reaper

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
 
C

Cor Ligthert

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
 

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