We help IT Professionals succeed at work.
Get Started

VB.net program to grab lines from files that contain a certain text pattern

Brian asked
Last Modified: 2019-12-03
I have the following code that iterates thru files ending in .dat within a folder. Now what I want to do is go into each file and grab one line at a time, and if that line contains "PO-", then I want to put it into an array. I'm thinking I need another loop (maybe another Next loop?). Can someone help me to grab lines containing "PO-" within these files and put them into an array? Thanks!
    Private Sub btnSaveReport_Click(sender As Object, e As EventArgs) Handles btnSaveReport.Click
            Dim arrayPOentries() As String
            Dim strSourceFileLocation As String = AppDomain.CurrentDomain.BaseDirectory + "_data/"
            Dim strDetinationFileLocation As String = tbSaveFileLocation.Text
            Dim Paths() As String = IO.Directory.GetFiles(strSourceFileLocation, "*.dat")
            For Each Path As String In Paths
                'another loop here?
        Catch ex As Exception
        End Try
    End Sub

Open in new window

Watch Question
Analyst Assistant
Distinguished Expert 2020
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE