473,378 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

vb.net streamreader - Characters Above ASCII 127

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
3 3767
* "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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jason Gleason | last post by:
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...
4
by: G.Esmeijer | last post by:
Friends, Want to read a textfile with characters that go above 7F ( ascii > 128) and put the results line by line in a string to process it further I used a streamreader to do so but the...
6
by: Jesper | last post by:
Hi, Im using a code snippet that reads a text file from disc and processes it using stream = new StreamReader(filename); Is it possible to assign a String instead of a file as the source of...
2
by: Ian Oldbury | last post by:
I'm having a problem reading from a flat file, in the file "£" and "»" exist however when i view the contents of the variable LineContents these characters don't exist. Has anyone got any...
7
by: Drew Berkemeyer | last post by:
Hello, I'm using the following code to read a text file in VB.NET. Dim sr As StreamReader = File.OpenText(strFilePath) Dim input As String = sr.ReadLine() While Not input Is Nothing...
7
by: sweetpotatop | last post by:
Hello, I have a txt file which has a few lines of special characters: This is A line from the text file: ...
4
by: George | last post by:
Hi, I am puzzled by the following and seeking some assistance to help me understand what happened. I have very limited encoding knowledge. Our SAP system writes out a text file which includes...
5
by: Rob | last post by:
Hi, I have a VB.Net application that parses an HTML file. This file was an MS Word document that was saved as web page. My application removes all unnecessary code generated by MS Word and does...
0
by: rajana | last post by:
Dear All, We have Ansi file with german characters (Ä / Ø) , We are using Streamreader to read the contents of the file. But Readline() not able to read the German characters. We tried all...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.