GetBetween Function [Grab text inbetween 2 HTML elements] 01-06-2013, 02:26 AM
#1
Function:
Usage:
Example:
Let's say you had a variable declared as "convo", and the data stored inside that variable was "Goon sucks at AF tutorials.", now the syntax for it all would be;
Now let's grab the "AF" out of the sentence.
Completed:
Which would pop up and say, "This tutorial is written on AF".
##
Example #2) WebBased
Hope I explained it clearly enoug, sorry if I didn't. It's my 1st "ever" tutorial
Code:
Private Function GetBetween(ByVal Start As Long, ByVal Data As String, _
ByVal StartString As String, ByVal EndString As String, _
Optional ByVal CompareMethod As CompareMethod = vbBinaryCompare) As String
Dim lonStart As Long, lonEnd As Long
'1. Find start string.
lonStart = InStr(Start, Data, StartString, CompareMethod)
If lonStart > 0 Then
'2. Move to end of start string.
lonStart = lonStart + Len(StartString)
'3. Find end string.
lonEnd = InStr(lonStart, Data, EndString, CompareMethod)
If lonEnd > 0 Then
'4. Extract data between start and end strings.
GetBetween = Mid$(Data, lonStart, lonEnd - lonStart)
End If
End If
End Function
Code:
GetBetween "IndexToStart, WhereToGet, FrontOfString,BackOfString"
Example:
Let's say you had a variable declared as "convo", and the data stored inside that variable was "Goon sucks at AF tutorials.", now the syntax for it all would be;
Code:
Dim Convo As String = "Goon sucks at AF Tutorials"
Completed:
Code:
Dim Convo As String = "Goon sucks at AF Tutorials"
Dim Forums As String = GetBetween(1,Convo,"sucks at","Tutorials")
MsgBox ("This tutorial is written on "" & Forums & "")
##
Example #2) WebBased
Hope I explained it clearly enoug, sorry if I didn't. It's my 1st "ever" tutorial