We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Extracting A Value From a String (HTML String)

Purified
Purified asked
on
Medium Priority
213 Views
Last Modified: 2010-04-30
Does anyone know how I can extract a string from a much larger string (an HTML source)?
Comment
Watch Question

Take a look @ Q.10068721.

This was something I helped a guy with.

Author

Commented:
I tried to use the code in that question, and it keeps returning nothing.  Any help?
deightonprog

Commented:
You want to search for a string within a larger string?
Where is the HTML string held?
deightonprog

Commented:
You want to search for a string within a larger string?
Where is the HTML string held?
prog
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
deightonprog

Commented:
'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

Author

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.....
deightonprog

Commented:
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?



Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.