Results 1 to 5 of 5

Thread: Find all words in string

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    128

    Find all words in string

    Hello,


    Code:
    lngPlace = 1
                    Do Until lngPlace = 0
                        lngPlace = InStr(lngPlace, Packet, "<a href=", vbTextCompare)
                            HAXXX = lngPlace + 8
                            lngPlace = lngPlace + 1
                            lngLength = InStr(HAXXX + 1, Packet, ">", vbTextCompare)
                            lngLength = lngLength - HAXXX
                            strUrl = RemoveFlack(Mid$(Packet, HAXXX, lngLength)) 'grab url
                            Text1.Text = Text1.Text & vbNewLine & strUrl 'add both to list
                        X = X + 1
                    Loop
    That is pritty much my loop, but I'm having trouble making it realize when to stop looping, could anybody help me?

  2. #2
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Find all words in string

    vb Code:
    1. Option Explicit
    2.  
    3. Function FindAllRef(Packet As String) As String
    4.    Const StartFlag = "<a href="
    5.    Const EndFlag = ">"
    6.    Dim n1 As Long
    7.    Dim n2 As Long
    8.    Dim sTemp As String
    9.    Dim sRef As String
    10.    
    11.    n1 = 1
    12.    Do
    13.       n1 = InStr(n1, Packet, StartFlag, vbTextCompare)
    14.       If n1 = 0 Then
    15.          Exit Do
    16.       End If
    17.       n1 = n1 + Len(StartFlag)
    18.       n2 = InStr(n1, Packet, EndFlag, vbTextCompare)
    19.       If n2 > 0 Then
    20.          sRef = Mid(Packet, n1, n2 - n1)
    21.          If sTemp <> "" Then
    22.             sTemp = sTemp & vbNewLine
    23.          End If
    24.          sTemp = sTemp & sRef
    25.          n1 = n2 + Len(EndFlag)
    26.       End If
    27.    Loop
    28.    
    29.    FindAllRef = sTemp
    30.      
    31. End Function
    32.  
    33. '-- Use function:
    34. '   Text1 = FindAllRef(aNewPacket)

  3. #3
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Find all words in string

    looks to me like it should exit as soon as it doesn't find anything, as long as you fix your first line.
    Code:
    lngPlace = InStr(lngPlace+ 1, Packet, "<a href=", vbTextCompare)
    in fact i am surprised it didn't return an error.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    128

    Re: Find all words in string

    Quote Originally Posted by anhn
    vb Code:
    1. Option Explicit
    2.  
    3. Function FindAllRef(Packet As String) As String
    4.    Const StartFlag = "<a href="
    5.    Const EndFlag = ">"
    6.    Dim n1 As Long
    7.    Dim n2 As Long
    8.    Dim sTemp As String
    9.    Dim sRef As String
    10.    
    11.    n1 = 1
    12.    Do
    13.       n1 = InStr(n1, Packet, StartFlag, vbTextCompare)
    14.       If n1 = 0 Then
    15.          Exit Do
    16.       End If
    17.       n1 = n1 + Len(StartFlag)
    18.       n2 = InStr(n1, Packet, EndFlag, vbTextCompare)
    19.       If n2 > 0 Then
    20.          sRef = Mid(Packet, n1, n2 - n1)
    21.          If sTemp <> "" Then
    22.             sTemp = sTemp & vbNewLine
    23.          End If
    24.          sTemp = sTemp & sRef
    25.          n1 = n2 + Len(EndFlag)
    26.       End If
    27.    Loop
    28.    
    29.    FindAllRef = sTemp
    30.      
    31. End Function
    32.  
    33. '-- Use function:
    34. '   Text1 = FindAllRef(aNewPacket)
    worked perfect, thanks

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Find all words in string

    If you consider this resolved, you could help us out by pulling down the Thread Tools menu and clicking the Mark Thread Resolved menu item. That will let everyone know that you have your answer.

    Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width