having a FileStream that I read with a StreamReader (it is a very large file), how can I set the Seek position of the FileStream to the first occurrence of a certain substring so that I can start reading this large file from a given point?
Thanks
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.
What’s in the file? Just lines of Unicode text? Then you’ve got a problem.
You will never know the position of the start of a line until you’ve read all the previous lines at least once. Unless the file is encoded in UTF-32, each character may take a variable number of bytes to represent it. Each line will have a variable length.
The best you can do is to scan through the file once and then make note of the positions of the starts of lines, in an index.