troubleshooting Question

find index in list of strings

Avatar of msout
msout asked on
Web Development Software
3 Comments1 Solution351 ViewsLast Modified:
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
       
                         
 
                 
   
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros