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
2009-09-04 03:11:25
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
2009-11-26 17:11:04