Get a chunck of text delimited by two strings
By: Lorenzo Dalla Vecchia Date: 23/06/2000

The following is a very short and useful function I wrote that "cuts" a chunck of text between two strings.
Copy the code into a module:

Public Function GetChunck(strString As String, _
strBegin As String, strEnd As String) As String
    Dim p0 As Integer, p1 As Integer
    p0 = InStr(strString, strBegin) + Len(strBegin)
    p1 = InStr(strString, strEnd)
    If p0 = 0 Or p1 = 0 Then GetChunck = "": Exit Function
    GetChunck = Mid(strString, p0, p1 - p0)
End Function

The use is very simple. Let's assume I have the string "this is a <test> string" and I want to retrieve the text between < and >:

strChunck = GetChunk("this is a <test> string", "<", ">")

strChunck will contain "test".

For another application of this function, see Retrieve the title of a HTML page.

Click Here!


Visual Basic Programming Zone is a website by Lorenzo Dalla Vecchia.
To contact the Webmaster, click here.
Hosted by InWind: www.inwind.it