![]() |
|
Tutorial GetBetween Function [Grab text inbetween 2 HTML elements] - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Visual Basic & .NET Framework (https://sinister.li/Forum-Visual-Basic-NET-Framework) +--- Thread: Tutorial GetBetween Function [Grab text inbetween 2 HTML elements] (/Thread-Tutorial-GetBetween-Function-Grab-text-inbetween-2-HTML-elements) |
GetBetween Function [Grab text inbetween 2 HTML elements] - zer0_s3c - 01-06-2013 Function: 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 FunctionCode: 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 RE: GetBetween Function [Grab text inbetween 2 HTML elements] - SQLi - 01-06-2013 Thanks man, this is very useful! I'd do it like this though: Code: dim x, y, z as string
x = "Hello, my name is SQLi. I work for the government."
y = x.split("is ")(1)
z = y.split(". I work")(0)RE: GetBetween Function [Grab text inbetween 2 HTML elements] - cxS - 02-25-2013 The function is using old and slow VB6 carry over methods. |