Extract Text from Text Block (1 Viewer)

mresann

Registered User.
Local time
Today, 02:56
Joined
Jan 11, 2005
Messages
357
In many cases, I’ve had the need to extract text from text blocks, such as HTML source pages, in a quick but highly comprehensive manner. The text is identified by providing the string for the text immediately to the left of the desired text, as well as providing the string for the text immediately to the right. While most programmers don’t have problems with string operations, the ability to have a universal procedure that allows for several text extraction options has made this function one of my most versatile text processing tools.

The module provided is very comprehensive, but there is a single line of code that can be ported to any other procedure (provided variables are pre-vetted). In addition, I've included a mini-tutorial on how to use this function. The code is clean and descriptive as well.

As a quick preview, here is the single line of code that peforms the meat of the function.

Code:
strExtractText = Mid(strTextBlock, (InStr(lngStart, strTextBlock, strLeft, lngCompare)) + _
      Len(strLeft), (InStr((InStr(lngStart, strTextBlock, strLeft, lngCompare)) + 1, _
      strTextBlock, strRight, lngCompare)) - ((InStr(lngStart, strTextBlock, strLeft, _
      lngCompare)) + Len(strLeft)))

The attached file contains the module as well as a tutorial that actually breaks down the function to its component parts, so you don't have to analyze this code.
 

Attachments

  • fncTextExtract.zip
    22.1 KB · Views: 519

Users who are viewing this thread

Top Bottom