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)?
PurifiedAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
deightonConnect With a Mentor Commented:
Heres a function which returns true if a text string is found in a source file (case sensitivity is in operation).  The line an position of text are returned in iline and ipos

Private Sub Command1_Click()

    Dim line As Long, pos As Long
     MsgBox ReturnPosition("a:html.txt", "deighton", line, pos)
     MsgBox "Found at line " & Str(line) & " position " & Str(pos)

End Sub

Private Function ReturnPosition(Source As String, SearchText As String, iLine As Long,    iPos As Long) As Boolean     'line wrapped format to one line please!

        Dim bFound As Boolean
        Dim sLine As String
       
        iLine = 0
        iPos = 0
       
        Open Source For Input As #1
       
        Line Input #1, sLine
       
        Do Until EOF(1) Or bFound
           
            iLine = iLine + 1
       
            x = InStr(sLine, SearchText)
           
            If x <> 0 Then
           
                iPos = x
                bFound = True
               
            End If
           
            Line Input #1, sLine
           
        Loop
       
        ReturnPosition = bFound
       
        Close #1
       
End Function
           
               



0
 
percosolatorCommented:
Take a look @ Q.10068721.

This was something I helped a guy with.
0
 
PurifiedAuthor Commented:
I tried to use the code in that question, and it keeps returning nothing.  Any help?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
deightonCommented:
You want to search for a string within a larger string?
Where is the HTML string held?
0
 
deightonCommented:
You want to search for a string within a larger string?
Where is the HTML string held?
0
 
deightonCommented:
'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
0
 
PurifiedAuthor Commented:
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.....
0
 
deightonCommented:
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?



0
All Courses

From novice to tech pro — start learning today.