Results 1 to 2 of 2

Thread: Advice / help reading this file to an array or better suggstion

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2016
    Posts
    22

    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.

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,711

    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width