C Graal C Graal - 4 months ago 13
Vb.net Question

Matching Word/ Text

normally i use element from webbrowser to add strings or tags from the webbrowser. This time i am using webclient to download the document text, as seen;

Dim sourceString As String = New System.Net.WebClient().DownloadString("hats,com")

So basically i download the document of a website, now this document has a bunch of websites starting with the same word, in this case > https, seen below.

"x" "https://hats.com/xxx", "x"

so im trying to get all the words (in this case links) that start with (https://hats.com/xxx) and add them to a listbox.

so first index will be the first match/ word that starts with the url, second index will be the second url found with same start.

Answer

I don't know understand exactly what you mean but maybe this will work (Try which one works best for you) I think you want the second one.

Dim str1 As String = TextBox1.Text
    str1 = str1.Replace(",", "")
    str1 = str1.Replace(" ", "")
    Dim str2 As String() = str1.Split({""""}, StringSplitOptions.RemoveEmptyEntries)
    Dim str3 As String = str2(0)
    For Each i In str2
        If i.StartsWith(str3) Then
            ListBox1.Items.Add(i)
        End If
    Next

Or

Dim str1 As String = TextBox1.Text
    str1 = str1.Replace(",", "")
    str1 = str1.Replace(" ", "")
    Dim str2 As String() = str1.Split({""""}, StringSplitOptions.RemoveEmptyEntries)
    For Each i In str2
        If i.StartsWith("https") Then
            ListBox1.Items.Add(i)
        End If
    Next

Replace TextBox1 with your textbox name and ListBox1 with your listbox name.

If neither of these work for you please explain better what you want and add some code you have tried.