vb.net - get strings between

XK8ER
XK8ER used Ask the Experts™
on
hello,
I am trying to get strings between html..
the ID in the code always changes so I wanted to know how to get the code between garden.. which is 5659195981

<li data="9849865659448">
  <span>Home & Kitchen</span>
</li>
<li data="5659195981">
  <span>Garden</span>
</li>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Kent DyerIT Security Analyst Senior

Commented:
something like..

If instr(Text,"5659195981")>0 Then
Wscript.Echo "Found the string"
Else
Wscript.Echo "Not there.."
End If

Open in new window


HTH,

Kent
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
*Not a web programmer, so there might some magic web functions to parse that html...no idea!

Here's an approach, though, using standard string functions:
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim html As String = "<li data=" & Chr(34) & "9849865659448" & Chr(34) & ">" & vbCrLf & vbTab & "<span>Home & Kitchen</span>" & vbCrLf & "</li>" & vbCrLf & "<li data=" & Chr(34) & "5659195981" & Chr(34) & ">" & vbCrLf & vbTab & "<span>Garden</span>" & vbCrLf & "</li>"
        Label1.Text = GetID(html, "Garden")
    End Sub

    Private Function GetID(ByVal html As String, ByVal listItem As String) As String
        Dim ID As String = ""
        Dim index As Integer = html.ToLower.IndexOf(listItem.ToLower)
        If index <> -1 Then
            Dim equals As Integer = html.LastIndexOf("=", index)
            If equals <> -1 Then
                Dim greaterThan As Integer = html.IndexOf(">", equals)
                If greaterThan <> -1 AndAlso greaterThan < index Then
                    ID = html.Substring(equals + 1, greaterThan - equals - 1).Trim(Chr(34))
                End If
            End If
        End If
        Return ID
    End Function

Open in new window

Author

Commented:
none of the code posted here works..

the complete html page has 15,000 lines so I dont want to post it here..

anyways I would like to know if it possible to do it?

Author

Commented:
basically what I need is to find <span>Garden</span>
then back out some characters to at least get

<li data="5659195981">
  <span>Garden</span>
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
My code looked for "Garden", and then backed up to find the value between the equals sign and the > symbol.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial