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
Who is Participating?
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()
        ' 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 _
        If m.Success Then
            prField = m.Groups(1).Value()
        End If

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

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.