Advice / help reading this file to an array or better suggstion
I receive a text file with unknow number of messages, which I need to read and process each message.
example of a message file. Each message starts with Message and ends with End Message
Message
From:Fred
Hi This is a test one line
End Message
Message:
From:John
This is a two line test
Second line
End Message
I'm looking for help on the best way to read the file and separate it into each message so I can to do some processing on the message content. The only way I could think of is reading it to an array but I'm not sure of how and some messages may have 100+ lines and there is an unknown number of messages in each file.
Re: Advice / help reading this file to an array or better suggstion
You could do this with a RegEx e.g.
Code:
Sub Main(args As String())
Dim message = "Message
From:Fred
Hi This is a test one line
End Message
Message:
From:John
This is a two line test
Second line
End Message"
Dim regex = New Regex("(?<=Message[\s\S]*?From:)[\s\S]*?(?=End Message)")
Dim matches = regex.Matches(message)
End Sub