Page 1 of 1

Read between strings

Posted: Mon May 23, 2011 11:18 am
by M1z23R
I need help reading string between strings xD for example "</xx>TEXT<xx/>
i want to read the "TEXT" between these two :)

Re: Read between strings

Posted: Mon May 23, 2011 11:51 am
by Scottie1972
WebBrowser1.Document.getElementByTagName
Code: Select all
Private Sub DisplayMetaDescription()
    If (WebBrowser1.Document IsNot Nothing) Then
        Dim Elems As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("META")

        For Each elem As HtmlElement In Elems
            Dim NameStr As String = elem.GetAttribute("name")

            If ((NameStr IsNot Nothing) And (NameStr.Length <> 0)) Then
                If NameStr.ToLower().Equals("description") Then
                    Dim ContentStr As String = elem.GetAttribute("content")
                    MessageBox.Show("Document: " & WebBrowser1.Url.ToString() & vbCrLf & "Description: " & ContentStr)
                End If
            End If
        Next
    End If
End Sub
WebBrowser1.Document.getElementById
Code: Select all
Private Function GetTableRowCount(ByVal TableID As String) As Integer
    Dim Count As Integer = 0

    If (WebBrowser1.Document IsNot Nothing) Then

        Dim TableElem As HtmlElement = WebBrowser1.Document.GetElementById(TableID)
        If (TableElem IsNot Nothing) Then
            For Each RowElem As HtmlElement In TableElem.GetElementsByTagName("TR")
                Count = Count + 1
            Next
        Else
            Throw (New ArgumentException("No TABLE with an ID of " & TableID & " exists."))
        End If
    End If
    GetTableRowCount = Count
End Function

Re: Read between strings

Posted: Mon May 23, 2011 12:24 pm
by mandai
It isn't clear how we would use the code above to get a substring.

You could use this:
Code: Select all
        Dim input As String = "</xx>TEXT<xx/>"
        Dim text As String = input.Remove(0, input.IndexOf(">"c) + 1)
        text = text.Remove(text.IndexOf("<"c))

        MsgBox(text)

Re: Read between strings

Posted: Mon May 23, 2011 6:39 pm
by M1z23R
Thanks guys :)