Reading / Parsing a text file

I need to read the characters that follow PR in the following text file.  I do not need to use an array, but I do need to put the characters into a variable so I can use them in a database query.  How can I do this?


#J 8.1
PD Lightbulb
PR 4568DM
PB B-54
LVL 4
HKComputerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi HKComputer;

Here is a solution using Regular Expressions.

Imports System.Text.RegularExpressions
Imports System.IO

        ' Read the file into memory
        Dim sr As New StreamReader("C:\Temp\MyFile.txt")
        Dim input As String = sr.ReadToEnd()
        sr.Close()
        ' The value of PR field if it is in the file
        Dim prField As String
        ' Regex Match object
        Dim m As Match

        ' Check to see if the file has the field and store it into prField
        ' if it does.
        m = Regex.Match(input, "^\s*?PR\s+(.*?)$", RegexOptions.Multiline Or _
            RegexOptions.IgnorePatternWhitespace)
        If m.Success Then
            prField = m.Groups(1).Value()
        End If

        ' Display the value of prField if it was found.
        If Not prField = "" Then
            MessageBox.Show(prField)
        End If


Fernando

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HKComputerAuthor Commented:
I've been busy with my Access projects but today I'm working on this one.  I'll post back in a little while.  Thanks -HK
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.