|
-
Aug 13th, 2007, 07:03 PM
#1
Thread Starter
Addicted Member
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?
-
Aug 13th, 2007, 08:26 PM
#2
Re: Find all words in string
vb Code:
Option Explicit
Function FindAllRef(Packet As String) As String
Const StartFlag = "<a href="
Const EndFlag = ">"
Dim n1 As Long
Dim n2 As Long
Dim sTemp As String
Dim sRef As String
n1 = 1
Do
n1 = InStr(n1, Packet, StartFlag, vbTextCompare)
If n1 = 0 Then
Exit Do
End If
n1 = n1 + Len(StartFlag)
n2 = InStr(n1, Packet, EndFlag, vbTextCompare)
If n2 > 0 Then
sRef = Mid(Packet, n1, n2 - n1)
If sTemp <> "" Then
sTemp = sTemp & vbNewLine
End If
sTemp = sTemp & sRef
n1 = n2 + Len(EndFlag)
End If
Loop
FindAllRef = sTemp
End Function
'-- Use function:
' Text1 = FindAllRef(aNewPacket)
-
Aug 13th, 2007, 08:29 PM
#3
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.
-
Aug 13th, 2007, 08:30 PM
#4
Thread Starter
Addicted Member
Re: Find all words in string
 Originally Posted by anhn
vb Code:
Option Explicit
Function FindAllRef(Packet As String) As String
Const StartFlag = "<a href="
Const EndFlag = ">"
Dim n1 As Long
Dim n2 As Long
Dim sTemp As String
Dim sRef As String
n1 = 1
Do
n1 = InStr(n1, Packet, StartFlag, vbTextCompare)
If n1 = 0 Then
Exit Do
End If
n1 = n1 + Len(StartFlag)
n2 = InStr(n1, Packet, EndFlag, vbTextCompare)
If n2 > 0 Then
sRef = Mid(Packet, n1, n2 - n1)
If sTemp <> "" Then
sTemp = sTemp & vbNewLine
End If
sTemp = sTemp & sRef
n1 = n2 + Len(EndFlag)
End If
Loop
FindAllRef = sTemp
End Function
'-- Use function:
' Text1 = FindAllRef(aNewPacket)
worked perfect, thanks
-
Aug 14th, 2007, 07:16 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|