?
Solved

Reading / Parsing a text file

Posted on 2006-04-15
5
Medium Priority
?
164 Views
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
0
Comment
Question by:HKComputer
2 Comments
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 1000 total points
ID: 16461503
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
0
 
LVL 4

Author Comment

by:HKComputer
ID: 16658490
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
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

840 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