Results 1 to 3 of 3

Thread: Webbrowser1 - Copy specific text automatically

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2014
    Posts
    159

    Webbrowser1 - Copy specific text automatically

    Good Morning,

    How do I copy a specific text when a page loads to a textbox?

    I tried the following:

    Code:
    Private Sub copybw()
    
            WebBrowser1.Document.ExecCommand("Copy", False, Nothing)
            If Clipboard.ContainsText Then
                TextBox10.Text = Clipboard.GetText()
            End If
    
        End Sub
    Code:
    Private Sub try1()
            Dim bodytext As String
            bodytext = WebBrowser1.Document.Body.InnerHtml
            If bodytext Like ("###*") Then
                copybw()
            End If
    
        End Sub
    
    
    
    Code:
    Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
     If Me.WebBrowser1.Document.Body.InnerHtml.Contains("BW") Then
                    try1()
    
                End If

  2. #2
    Frenzied Member
    Join Date
    Oct 2012
    Location
    Tampa, FL
    Posts
    1,187

    Re: Webbrowser1 - Copy specific text automatically

    Could try something like this:

    Code:
            Dim sourceString = "This is a test"
            Dim searchString = "test"
    
            Dim index As Integer = sourceString.IndexOf(searchString)
    
            If index <> -1 Then
                Dim theStringValueYouWant = sourceString.Substring(index, searchString.Length)
            End If
    SourceString would be the textbox text, or the string you want to look through. You then see if your search string occurs in that string, if so, you can get the index, and from there use .substring() to pull from that point, to the length of the string. However, at that point you could just use .Contains() if you didnt need the value. It sounds like you are asking because you need to pull items before or after the actual occurence.

    Code:
    Dim sourceString = "This is a test12345"
            Dim searchString = "test"
    
            Dim index As Integer = sourceString.IndexOf(searchString)
    
            If index <> -1 Then
                Dim theStringValueYouWant = sourceString.Substring(index + searchString.Length, 5)
            End If
    In this scenario, you have a group of numbers that occur after Test. This shows you how you could pull those numbers since you may not know what they will be, but you know where they will occur.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2014
    Posts
    159

    Re: Webbrowser1 - Copy specific text automatically

    thank you, testing it now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width