Avatar of 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
End sub

Shared Function FindStr(ByVal oneLine As String) As Boolean

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

            Return True
            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
Web Development Software

Avatar of undefined
Last Comment

8/22/2022 - Mon


Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

I found solution
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck