find index in list of strings

msout
msout used Ask the Experts™
on
I have a text file which needs to be formatted. I need to find index of some of the lines. This is my code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       
      Dim filename As String = "C:\temp\Water Purge THM&VOC 061311_20110707_11.rqt"
        Dim Lines As New List(Of String)(IO.File.ReadAllLines(filename))
        Dim oneLine As String = String.Empty
       
        Dim fileReader As New StreamReader(filename)
        Do While fileReader.Peek() <> -1
            For i As Integer = 0 To Lines.Count - 1
                oneLine = fileReader.ReadLine

                If oneLine.Length > 0 Then

                    Dim FindIndex As Integer = (Lines.FindIndex(AddressOf FindStr))
                   
 Response.Write("found  " & FindIndex)
                End If
                    Next
                Loop
End sub

Shared Function FindStr(ByVal oneLine As String) As Boolean

        If oneLine.Substring(0, 4) = "2001" Then

            Return True
        Else
            Return False
        End If

    End Function
I receive error message:

Index and length must refer to a location within the string.
Parameter name: length
 I assume that it is because there are empty lines but how can I resolve the problem?

Please, help
       
                         
 
                 
   
Comment
Watch Question

Do more with

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

Author

Commented:
.
Commented:
I found solution!
 Dim filename As String = "C:\temp\Water Purge THM&VOC 061311_20110707_11.rqt"
        Dim Lines As New List(Of String)(IO.File.ReadAllLines(filename))
        Dim oneLine As String = String.Empty
        Dim result As New List(Of Integer)
        Dim fileReader As New StreamReader(filename)
        Do While fileReader.Peek() <> -1
            oneLine = fileReader.ReadLine
            For i As Integer = 0 To Lines.Count - 1
                If Lines(i).Contains("2011") Then

                    Response.Write(i & " ")
                    result.Add(i)
                End If
            Next

        Loop

        Dim strItem As String
        For Each strItem In result
            Response.Write(strItem & "<br>")
        Next
           
           End Sub

Author

Commented:
I found solution

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