Help parsing file

Hello experts:

I've got mucho text files that I need to parse and extract specific information from.   Here is a sample of one of the documents needed to be parsed:

########################################################################
Re:  Tract 2 Highway 1020                              File No.: 78213b
                                                       County: Bullitt  
                                     
1.   Effective Date: February 28, 2003 at 8:00 AM
2.   Policy to be issued:
                                         
     (a)  ALTA OWNER Policy: 10-17-92   Amount    $                            

     Proposed Insured:
                                                   
     (b)  ALTA LOAN Policy: 10-17-92    Amount    $995,000.00          

     Proposed Insured:  
                         National City Bank of Kentucky

3.   The  land referred to herein is situated in Bullitt County,  Kentucky,      
     and described as follows:

.lm10
.rm65
                        (SEE DESCRIPTION ATTACHED)
.lm1
.rm75

2002 State, County & School Tax Parcel #034-000-00-019B                            
Assessment: $174,732.00   Bill #29284    Acct. #4193410-01
Face Amount: $1,387.90 paid on December 30, 2002
########################################################################

From this document(s) I need to extract the following information:

The Parcel # - Identified by Parcel #
The File Number - identified by File No:
The Address - identified by Re:
The County - identified by County:

So far, I have opened the file using a Streamreader object and I'm dumping the contents of the file into a string variable.  

Dim sr As StreamReader = New StreamReader(DocumentPath)
Dim srString As String
 
srString = sr.ReadToEnd
     
Now, the only snafu is that there may be multiple Parcel #, but each parcel number will be on its own line and identified by the tag Parcel #

Any help appreciated - I'm using VB.NET 2003.

LVL 4
escheiderAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Bob LearnedConnect With a Mentor Commented:
Try this:

  Public Sub ParseDocument(ByVal documentPath As String, ByRef address As String, ByRef fileNumber As String, ByRef county As String, ByRef parcels() As String)

    Dim sr As StreamReader = New StreamReader(documentPath)

    Dim listParcels As New ArrayList
    Dim text As String = ""

    While sr.Peek() <> -1

      Dim input As String = sr.ReadLine()

      Dim addressPos As Integer = input.IndexOf("Re:")

      If addressPos <> -1 Then
        address = input.Substring(addressPos + 3).Trim()

        Dim spacesPos As Integer = address.IndexOf("   ")

        If spacesPos <> -1 Then
          address = address.Substring(0, spacesPos).Trim()
        End If

      End If

      Dim filePos As Integer = input.IndexOf("File No.:")
      If filePos <> -1 Then
        fileNumber = input.Substring(filePos + 9).Trim()
      Else
        Dim countyPos As Integer = input.IndexOf("County:")

        If countyPos <> -1 Then
          county = input.Substring(countyPos + 8).Trim()
        Else
          Dim parcelPos As Integer = input.IndexOf("Parcel #")

          If parcelPos <> -1 Then
            listParcels.Add(input.Substring(parcelPos + 8).Trim())
          End If
        End If
      End If

    End While

    parcels = listParcels.ToArray(GetType(String))

  End Sub

Bob
0
 
doraiswamyCommented:
Maybe you can use "instr" and track each occurrence of "Parcel #" in the string.
0
 
escheiderAuthor Commented:
Thank you sir .. works great!!
0
All Courses

From novice to tech pro — start learning today.