Link to home
Start Free TrialLog in
Avatar of Purified
Purified

asked on

Extracting A Value From a String (HTML String)

Does anyone know how I can extract a string from a much larger string (an HTML source)?
Avatar of percosolator
percosolator

Take a look @ Q.10068721.

This was something I helped a guy with.
Avatar of Purified

ASKER

I tried to use the code in that question, and it keeps returning nothing.  Any help?
You want to search for a string within a larger string?
Where is the HTML string held?
You want to search for a string within a larger string?
Where is the HTML string held?
ASKER CERTIFIED SOLUTION
Avatar of deighton
deighton
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
'Heres the function again with a bug corrected - it wasn't reading the last line of text in properly!

Private Function ReturnPosition(Source As String, SearchText As String, iLine As Long, iPos As Long) As Boolean

        Dim bFound As Boolean
        Dim sLine As String
       
        iLine = 0
        iPos = 0
       
        Open Source For Input As #1
       
       
       
        Do Until EOF(1) Or bFound
           
            Line Input #1, sLine
           
            iLine = iLine + 1
       
            x = InStr(sLine, SearchText)
           
            If x <> 0 Then
           
                iPos = x
                bFound = True
               
            End If
           
        Loop
       
        ReturnPosition = bFound
       
        Close #1
       
End Function
I tried the code given above, and it returns Line 0 Position 0 Everytime, no matter what I have in the file, or am searching for.....
If the string is not found then the function itself returns false - the fact that line = 0 suggests that the file you are opening has no lines of text in it.

Here's the call I used - you need to get the path right etc.

Private Sub Command1_Click()
    Dim line As Long, pos As Long
     MsgBox ReturnPosition("a:html.txt", "browser", line, pos)
     MsgBox "Found at line " & Str(line) & " position " & Str(pos)
End Sub

Remember the search is case sensitive - you'd stop this with

            x = InStr(sLine, SearchText)

CHANGES TO

            x = InStr(ucase(sLine), ucase(SearchText))

note i have tested it on my PC - try running it in debug perhaps and see what line input returns?