Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Extracting A Value From a String (HTML String)

Posted on 1998-08-13
8
Medium Priority
?
200 Views
Last Modified: 2010-04-30
Does anyone know how I can extract a string from a much larger string (an HTML source)?
0
Comment
Question by:Purified
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 2

Expert Comment

by:percosolator
ID: 1468811
Take a look @ Q.10068721.

This was something I helped a guy with.
0
 

Author Comment

by:Purified
ID: 1468812
I tried to use the code in that question, and it keeps returning nothing.  Any help?
0
 
LVL 18

Expert Comment

by:deighton
ID: 1468813
You want to search for a string within a larger string?
Where is the HTML string held?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 18

Expert Comment

by:deighton
ID: 1468814
You want to search for a string within a larger string?
Where is the HTML string held?
0
 
LVL 18

Accepted Solution

by:
deighton earned 100 total points
ID: 1468815
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
 
LVL 18

Expert Comment

by:deighton
ID: 1468816
'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
 

Author Comment

by:Purified
ID: 1468817
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
 
LVL 18

Expert Comment

by:deighton
ID: 1468818
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question