Results 1 to 3 of 3

Thread: Do until match instead of endofstream

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    58

    Do until match instead of endofstream

    Code:
                
    Dim xRead As StreamReader = New StreamReader(FilePath, System.Text.Encoding.Default)
    
    Dim R As New Regex("""(.*)"",""" & MyTextbox.Text & "(.*)"",""(.*)"",.")
                'read the file
                Do Until xRead.EndOfStream
                    For Each M As Match In R.Matches(xRead.ReadLine)
                        MexIDResultTB.Text = M.Groups(1).Value
                        CompanyNameTB.Text = M.Groups(3).Value
                    Next
                Loop
    I need something like

    Read the file line by line until a match is found then exit the loop

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Do until match instead of endofstream

    You actually have to do both. It wouldn't be wise to not include something to end when the end of the stream is found, even if you are reasonably certain that there will always be a match.

    Therefore, what you need to do is signal the loop that it is time to end. For instance, you could add a boolean variable outside of the loop, and when a match is found, set the variable to True. The loop would then be until either the variable is True OrElse the end of stream is found.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    58

    Re: Do until match instead of endofstream

    Quote Originally Posted by Shaggy Hiker View Post
    You actually have to do both. It wouldn't be wise to not include something to end when the end of the stream is found, even if you are reasonably certain that there will always be a match.

    Therefore, what you need to do is signal the loop that it is time to end. For instance, you could add a boolean variable outside of the loop, and when a match is found, set the variable to True. The loop would then be until either the variable is True OrElse the end of stream is found.
    Hello, Shaggy, could you give me an example please!?

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