Link to home
Create AccountLog in
Avatar of msout
msout

asked on

find index in list of strings

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
       
                         
 
                 
   
Avatar of msout
msout

ASKER

.
ASKER CERTIFIED SOLUTION
Avatar of msout
msout

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of msout

ASKER

I found solution