I am parsing a very large file of records (one in each line, each of which has a different length), and I would like to keep track of the number of bytes that I read in the file so that I can recover from the failure event.
I wrote the following:
using (TextReader myTextReader = CreateTextReader())
{
string record = myTextReader.ReadLine();
bytesRead += record.Length;
ParseRecord(record);
}
However, this will not work, since it ReadLine()removes any CR / LF characters in the string. Alternatively, the line can be terminated with the characters CR, LF or CRLF, which means that I cannot just add 1 to bytesRead.
Is there an easy way to get the actual string length or write my own method ReadLine()in terms of granular operations Read()?
source
share