Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I obtain this text string?

Status
Not open for further replies.

Narboule

IS-IT--Management
Apr 29, 2003
19
FR
I'm updating an old project where we download an html file and extract information from it. Below is the old code. What I need to do is search for a particular html string that is a unique occurence in the text, then extract from the file, for example, the next 6 characters to the right of the string. Can anyone tell me a simple way to do this? I don't completely understand the old code and wouldn't mind understanding what's going on there either. Thanks.

Code:
Public Function Get_Hour(text As String) As String

    Searchstr = &quot;<td class=&quot;&quot;cell&quot;&quot;><font SIZE=&quot;&quot;-1&quot;&quot;>Hour</font></td>&quot;
    position = InStr(text, Searchstr) + Len(Searchstr)
    position = InStr(position, text, &quot;<td class=&quot;&quot;cell&quot;&quot;><font SIZE=&quot;&quot;-1&quot;&quot;>Header1</font></td>&quot;) + 50
    position = InStr(position, text, &quot;<td class=&quot;&quot;cell&quot;&quot;><font SIZE=&quot;&quot;-1&quot;&quot;><b>&quot;) + 36
    Get_Hour = Mid$(text, position, 5)
End Function

Public Function Get_Date(text As String) As String

    Searchstr = &quot;<td  class=&quot;&quot;cell&quot;&quot;><font SIZE=&quot;&quot;-1&quot;&quot;>Date</font></td>&quot;
    position = InStr(text, Searchstr) + Len(Searchstr)
    position = InStr(position, text, &quot;<td class=&quot;&quot;cell&quot;&quot;><font SIZE=&quot;&quot;-1&quot;&quot;>&quot;) + 34
    position = InStr(position, text, &quot;<td class=&quot;&quot;cell&quot;&quot;><font SIZE=&quot;&quot;-1&quot;&quot;>&quot;) + 37
    position2 = InStr(position, text, &quot;</b></font></td>&quot;)
    Searchstr = Left$(text, position2 - 1)
    Get_Date = Right$(Searchstr, 10)
End Function

 
I was retrieve it into an old application of mine dinamic data from active server page. So I needed from there certain fields. So I put one special character to delimit my dinamic field like:
Code:
~MyField~

My Code was something like this:
Code:
Public Function ExtractThis(htmlfile as string) as string
dim extract as string, ex as string, mycount as integer, cicle as long
for cicle=1 to len(htmlfile)
extract = mid(htmlfile,cicle,1)
if extract = &quot;~&quot; then mycount = mycount+1
if mycount = 2 then goto MyEnd
if mycount = 1 then ex = ex & extract
next
MyEnd:
extractthis = ex
end function
I wrote just now the code, but you will get my solution very easy I hope.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top