如何编写 VB.Net 方法来过滤 URL?
How do I write a VB.Net method to filter a URLs?
我正在尝试使用 VB.NET 编写一个方法,该方法允许我读入 URL 并将其与列表进行比较。如果它是列表中的 URL 之一,则将应用 Bing 跟踪转换。
目前我只能认为将它写成比较方法,将当前 URL 与需要跟踪的方法(列表)进行比较。然而,这似乎有点啰嗦。
每个页面可能有一个不同的查询字符串 value/page id,其基础是获取要应用跟踪的正确页面。
有什么想法吗?
不好意思我在VB.Net开发函数的时候真的是新手
如果我要使用 th Contains() 函数,那么我会想象它看起来有点像这样:
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
如果我要使用它,那么我必须使用什么类型的循环来 运行 检查我列表中的所有 URL 是否与 current_URL 相对照?另外,我将在哪里定义 current_URL?
您可以使用 Contains() function to check if the list contains the given value. You could also implement a binary search,但它可能对您的目的来说太过分了。这是一个例子:
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
确保添加这些导入 Imports System
和 Imports System.Collections.Generic
免责声明:我没有使用 VB.NET
的经验
我正在尝试使用 VB.NET 编写一个方法,该方法允许我读入 URL 并将其与列表进行比较。如果它是列表中的 URL 之一,则将应用 Bing 跟踪转换。 目前我只能认为将它写成比较方法,将当前 URL 与需要跟踪的方法(列表)进行比较。然而,这似乎有点啰嗦。 每个页面可能有一个不同的查询字符串 value/page id,其基础是获取要应用跟踪的正确页面。 有什么想法吗?
不好意思我在VB.Net开发函数的时候真的是新手 如果我要使用 th Contains() 函数,那么我会想象它看起来有点像这样:
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
如果我要使用它,那么我必须使用什么类型的循环来 运行 检查我列表中的所有 URL 是否与 current_URL 相对照?另外,我将在哪里定义 current_URL?
您可以使用 Contains() function to check if the list contains the given value. You could also implement a binary search,但它可能对您的目的来说太过分了。这是一个例子:
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
确保添加这些导入 Imports System
和 Imports System.Collections.Generic
免责声明:我没有使用 VB.NET
的经验