Read CSV file and skip some lines

chadmanvb
chadmanvb used Ask the Experts™
on
How can I setup a loop to read a csv file and skip some lines.  I would like it to skip the lines that:
skip blank lines, lines that start with a ";", lines where the second char="L", and skip lines that start with an alpha char

Below is what I have so far and I think that will skip the blank and the lines that start with ";"
Thanks, Chad
'*******************READ CSV***********************************
        Dim strUserFile As New StreamReader(workstationstext)
        Dim strPasswordstoReset As String = strUserFile.ReadToEnd()
        Dim strUserFileSplit() As String = Regex.Split(strPasswordstoReset, "\r\n")
        strUserFile.Close()
 
        'read each line and skip blank lines, lines that start with a ";", lines where the second char="L", and skip lines that start with an alpha char
        For Each Line As String In strUserFileSplit
            If Line <> "" Or Line.StartsWith(";") Then   '????????????????
 
 
 
            Else
                'do stuff
                Line = Line.ToLower.Trim
 
            End If
 
 
        Next

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Try this code. I just added 'Do Nothing comment after if.
'*******************READ CSV***********************************
        Dim strUserFile As New StreamReader(workstationstext)
        Dim strPasswordstoReset As String = strUserFile.ReadToEnd()
        Dim strUserFileSplit() As String = Regex.Split(strPasswordstoReset, "\r\n")
        strUserFile.Close()
 
        'read each line and skip blank lines, lines that start with a ";", lines where the second char="L", and skip lines that start with an alpha char
        For Each Line As String In strUserFileSplit
            If Line <> "" Or Line.StartsWith(";") Then   '????????????????
               'Do Nothing
 
 
            Else
                'do stuff
                Line = Line.ToLower.Trim
 
            End If
 
 
        Next

Open in new window

Author

Commented:
I have that part, I was not sure how to skip lines where the second char="L" and skip lines that start with an alpha char
Commented:
try to use substr function.

If Line.Substring(1, 1) = "L" Then
 'Do Nothing

Author

Commented:
That works great, but still need to skip the line if the first char in the line is an alpha char.
Commented:
This will check if the line starts with alpha characters...

  If IsNumeric(Line.Substring(0, 1)) = False Then
   'Do nothing...
  End If

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial