Finding a character in a file

jamie_pattison

Well-known member
Joined
Sep 9, 2008
Messages
116
Programming Experience
Beginner
Using a streamreader, im trying to find a character in a file. Ive got the basic code but not sure how i can go through the file to find this character. Could someone advise with some sample code?

Many Thanks
 
Hello.

You could simply go through line and line and let the String.Contains() look for it:
VB.NET:
Dim strmRdr as New IO.StreamReader(yourFile)

'Line for line
If strmRdr.ReadLine().Contains(yourCharacter) Then 'do something

'Read it at once
If strmRdr.ReadToEnd().Contains(yourCharacter) Then 'do something

strmRdr.Close()

For more complex things I'd suggest that you use System.Text.RegularExpressions.RegEx.

Bobby
 
Back
Top