Share via

Custom File Reader

StewartBW 1,905 Reputation points
2024-08-29T00:50:55.12+00:00

Hello,

I'm going to read Mbox rd files, for example Google takeout, they are simply a collection of normal rfc-822 email files, the tip is that beginning of each email is:

From xxxvbLf

The starting line begins with From and one space, then some chars and finally a vbLf (not vbCrLf)

So it must begin with "From " and ends with vbLf, each email also ends with a blank line: vbCrLf

Using sr As New StreamReader(file, True)
While Not sr.EndOfStream
    sr.ReadLine
End While

I've no idea if StreamReader is the way to go, because its .ReadLine will not return the ending vbLf

The file can be huge so read all text at once is not an option, should be read message by message, and split by lines that start with From and ends with vbLf

Any tip on the correct algorithm is appreciated.

Thanks in advance :)

Developer technologies | VB
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Jiachen Li-MSFT 34,241 Reputation points Microsoft External Staff
    2024-08-29T07:08:34.38+00:00

    Hi @StewartBW ,

    StreamReader.ReadLine() strips the line endings (vbCrLf, vbLf, or vbCr) before returning the line. Therefore, vbLf is no longer present in the returned string.

    TextFieldParser does not support delimiters that contain end-of-line characters.

    You can distinguish between mails by checking the blank line and the "From " in the next line.

    Best Regards.

    Jiachen Li


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

  2. Viorel 127K Reputation points
    2024-08-29T01:24:31.3666667+00:00

    Briefly, check if ReadLine returns a line that starts with “From ” .

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.