Reading / Parsing a text file

Posted on 2006-04-15
Last Modified: 2010-04-23
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
Question by:HKComputer
    LVL 62

    Accepted Solution

    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

    LVL 4

    Author Comment

    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

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now