0

Hello I am attempting to parse multiple lines of text from a text file using regexpressions. I am using vb.net with visual studio 2008.

At the moment I am filling my datatable with the text file information and am able to return each line of text and parse the first set of numbers that I am attempting to break up. I have multiple string with varying lengths of character lengths and numeric lengths however the delimiters are sometimes different. Sometimes will be whitespace and sometimes will be whitespace and chars. But is always 2 spaces.

Here is my code:

Dim myTbl As New DataTable("table")
        myTbl.Columns.Add("full path", GetType(String))
        myTbl.Columns.Add("number1", GetType(String))
        Dim Reader As System.IO.StreamReader = New System.IO.StreamReader(_strFile)
        Dim Line As String
        Dim drow As DataRow
        Dim numberFormat1 As String = "^([0-9]{2}-)[0-9]{1}-[0-9]{2}\s*"


        Do
            Line = Reader.ReadLine
            If Line Is Nothing Then
                Exit Do
            End If
            LineMod = Line.Remove(0, 3)

                    
            Dim myMatch1 As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(LineMod, numberFormat1)

            If myMatch1.Success Then
                number1 = myMatch1.ToString
            Else
                number1 = String.Empty
            End If

          
            Dim sAry As String() = LineMod.Split()
            Dim PAry As String() = number1.Split()
            drow = myTbl.NewRow
            drow(0) = SAry(0)
            drow(1) = PAry(0)
            myTbl.Rows.Add(drow)

        Loop
        
        Reader.Close()

This number format I have declared can possibly occur more than once in each line and will always be consistent. It will always be seperated by 2 white space or alpha-character and will always appear at the beginning of the line. How can I have my code check to see if the number format occurs more than once in a line and if so add it to my datatable in a new row.

Edited by starlight849: Version

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by starlight849
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.