By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,479 Members | 988 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,479 IT Pros & Developers. It's quick & easy.

vb.net streamreader - Characters Above ASCII 127

P: n/a
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()
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
* "pabelard" <an*******@discussions.microsoft.com> scripsit:
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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2

P: n/a
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

"pabelard" <an*******@discussions.microsoft.com> wrote in message
news:2d*****************************@phx.gbl...
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()

Nov 20 '05 #3

P: n/a
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
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.