简体   繁体   中英

How do I write a VB.Net method to filter a URLs?

I am attempting to write a method using VB.NET that will allow me to read in a URL and compare it to a list. If it is one of the URLs on the list then Bing Tracking conversion will be applied. At the moment I can only think do write it as a comaparative method, comapring the current URL with the ones that require tracking (a list). This, however, sems a little long winded. Each page may have a different querystring value/page id, there for its fundamental to get exactly the right page for the tracking to be applied to. Any Ideas?

Sorry I really am a novice when developing functions in VB.Net If I were to use th Contains() function then I would imagine that it would look a little something like this:

Private sub URL_filter (ByVal thisPage As ContentPage, brandMessage? As   Boolean) As String
    Dim url_1 As String = "/future-contact thanks.aspx"
    Dim url_2 As String = "/find-enquiry thanks.aspx?did=38"                                                          
    Dim url_3 As String = "/find-enquiry-thanks.aspx?did=90"
    Dim url_4 As String = "/find-enquiry-thanks.aspx?did=62"    
    Dim result as String

    result = CStr (url_1.Contains(current_URL))

    txtResult.Text = result 
End Sub 

If I were to use this then what type of loop would I have to run to check all the URLs that are in my list against the current_URL? Also where would I define the current_URL?

You can use the Contains() function to check if the list contains the given value. You could also implement a binary search , but it is probably overkill for your purposes. Here is an example:

Dim UrlList As New List(Of String)
UrlList.Add("www.example2.net") 'Just showing adding urls to the list
UrlList.Add("www.example3.co.uk")
UrlList.Add("www.exampletest.com")

Dim UrlToCheck As String = "www.exampletest.com" 'This is just an example url to check

Dim result As Boolean = UrlList.Contains(UrlToCheck) 'The result of whether it was found

Make sure to add these imports Imports System and Imports System.Collections.Generic

Disclaimer: I have no experience with VB.NET

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM