Searching a String

Discussion in 'Programming General' started by PhanTomX, Dec 21, 2009.

Searching a String
  1. Unread #1 - Dec 21, 2009 at 1:27 PM
  2. PhanTomX
    Joined:
    Apr 24, 2005
    Posts:
    9
    Referrals:
    0
    Sythe Gold:
    0

    PhanTomX Newcomer

    Searching a String

    I could have titles this better... I want to do something more link split string into an array..
    What I'm wanting to do is: Open a web page, and get the text from a certain line

    So far I have:
    Code:
            For i As Integer = 0 To lstItemIDs.Items.Count - 1
                Try
                    request = request.Create(Link) 'link edited out for a couple of reasons
                    response = request.GetResponse()
                    stream = New StreamReader(response.GetResponseStream())
                    If InStr(stream.ReadToEnd(), "Error") Then
                        lstErrors.Items.Add(lstItemIDs.Items(i))
                    Else
                        Dim webLines() As String = Split(stream.ReadToEnd, vbNewLine)
                        lstItemNames.Items.Add(webLines(142))
                    End If
                Catch ex As Exception
                    lstErrors.Items.Add(lstItemIDs.Items(i))
                End Try
    
    I get the error that the index was outside the bounds of the array
    Any help appreciated
     
  3. Unread #2 - Dec 21, 2009 at 5:16 PM
  4. Harlem9191
    Joined:
    Mar 10, 2009
    Posts:
    81
    Referrals:
    0
    Sythe Gold:
    0

    Harlem9191 Member

    Searching a String

    Are you sure you have the right line?
    That error pops up obviously when it can't find the line.
     
  5. Unread #3 - Dec 21, 2009 at 8:16 PM
  6. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    Searching a String

    Code:
    lstItemNames.Items.Add(webLines(142))
    Don't use "Magic Numbers". Define what that number is in a constant and then refer to that constant. Not only will it help you when you read over it, it will help other coders who want to resolve your issue.
     
< JAVA : DICE ROLLS 20 TIMES and PRINTS THE RESULT | CMD Command with TextBoxX.Text >

Users viewing this thread
1 guest


 
 
Adblock breaks this site