1 Replies - 357 Views - Last Post: 05 December 2016 - 04:34 PM Rate Topic: -----

#1 Aquiteus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 24-October 16

how to have a regular expression check the text in a text file

Posted 05 December 2016 - 01:53 PM

i have a oledbdatareader rdr that is reading from a csv file im trying to make it so before the program runs the bulk of my code it checks to make sure the format is correct but i dont know what to reference to check with "myRegex.IsMatch()" here is a portion of my code:

Dim DDAta As New List(Of DataItem)
                Dim rdr As OleDbDataReader = olecmd.ExecuteReader

                infoReader = My.Computer.FileSystem.GetFileInfo(FileName)

                'Since we have specified HDR=YES in the connection string, the data will loop from Row 2 onwards
                Dim myRegex As New Regex("<regular expression>")
                If myRegex.IsMatch(rdr) = True Then


Is This A Good Question/Topic? 0
  • +

Replies To: how to have a regular expression check the text in a text file

#2 Aquiteus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 24-October 16

Re: how to have a regular expression check the text in a text file

Posted 05 December 2016 - 04:34 PM

i was able to make a messy work-around:
Do While rdr.Read()
                    Dim myRegex As New Regex("\d{1,2}[/]\d{1,2}[/]\d{4},\d{6},\D{6,},\d{9},\D{4}\d{4}\D{1}\d{1},(?:CR|IN),\d{1,},\d{1,2}[/]\d{1,2}[/]\d{4},\d{5}-\d{8}-\d{4}-\d{4}")
                    Dim line As String = rdr.GetValue(0) & "," & rdr.GetValue(1) & "," & rdr.GetValue(2) & "," & rdr.GetValue(3) & "," & rdr.GetValue(4) & "," & rdr.GetValue(5) & "," & rdr.GetValue(6) & "," & rdr.GetValue(7) & "," & rdr.GetValue(8)
                    If myRegex.IsMatch(line) = True Then
                        Dim thisItem As New DataItem
                        thisItem.InDate = Format(rdr.GetDateTime(0).ToString, "dd-MMM-yy")
                        thisItem.InNum = rdr.GetValue(1)
                        thisItem.StuName = rdr.GetString(2)
                        thisItem.StuID = rdr.GetValue(3)
                        thisItem.ProCode = rdr.GetString(4)
                        thisItem.INCR = rdr.GetString(5)
                        thisItem.Amt = rdr.GetValue(6)
                        thisItem.TransDate = Format(rdr.GetDateTime(7).ToString, "dd-MMM-yy")
                        thisItem.TransNum = rdr.GetString(8)
                        thisItem.TrmCd = TermCode
                        thisItem.EffectDate = Format(infoReader.CreationTime, "dd-MMM-yy")
                        DDAta.Add(thisItem)
                        ProgressBar1.Value = ProgressBar1.Value + 125
                        System.Threading.Thread.Sleep(500)
                    Else
                        MsgBox("The format is incorrect")
                        ProgressBar1.Value = 0
                        rdr.Close()
                        Exit Do
                    End If
                    Loop


this was hammered in between my normal code so im happy to read any suggestions for a better way

This post has been edited by Aquiteus: 05 December 2016 - 04:35 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1