views:

128

answers:

2

how to read a text file character by character in VB.NET??

+4  A: 
Using reader As New System.IO.StreamReader( "yourfile.txt" )
    While Not reader.EndOfStream
        Dim buffer(1) As Char
        reader.Read(buffer, 0, 1)
        'do something with buffer(0)'
    End While
End Using

As Jayden suggested, you would normally read a file line-by-line. I'm taking for granted that you have some reason for wanting to do so one character at a time.

harpo
A: 

It's pretty slow to read a byte at a time, but Harpo's answer will do that. If you want an alternative, b = System.IO.ReadAllBytes(filename) will be a lot faster, and then you can process the data one byte at a time in the byte array b. Alternatively, you can use s = System.IO.ReadAllText(filename) and process the characters in the string s.

xpda