The file is a UTF8 text files.
Each characters has varying number of bytes and each line has varying number of characters.
Does vb.net has table of line numbers to byte location function or something like that?
Also after that how to read that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
StreamReaderclass is the typical choice for line-by-line reading of a file. It does not maintain any history of what it reads in a file and thus does not know where the last line ended or where the next one will. When requested (viaReadLine), it simply processes characters until it reaches the new line string or the end of the file.I do not know the actual implementation of the StreamReader, but I would assume that it uses the
Encodingclass to handle multi-byte encodings and only maintains a small buffer of potentially pre-read data to improve read performance (reading chunks is better than just the 10 bytes you need now). Any other buffers, such as the characters in the current line, would be locals to functions likeReadLinethat need them.If you need to seek randomly, you will need to use the
BaseStreamproperty to generate a table of line starts for yourself and then seek that stream to the beginning of the desired line. From there, you should be able to useReadLineas usual.