0

我编写了少量代码来将 url 修剪到最后一个路径,直到到达主机,但它不能正常工作:

Dim line As String
line = "http://www.domain.com/folder1/folder2/folder3/folder4/"
line = Replace(line, "http://", "")

Dim count As Integer
count = line.Split("/").Length - 1

For x = count To 1 Step -1
    count = line.Split("/").Length - 1
    Dim lastpath As String = line.Split("/")(x).Split("/")(0)
    Dim newline As String = Replace(line, "/" & lastpath, "")
    MsgBox(newline)

在我的情况下,我希望看到 5 个带有 url 且没有最后路径的框消息:

www.domain.com/folder1/folder2/folder3/folder4
www.domain.com/folder1/folder2/folder3
www.domain.com/folder1/folder2
www.domain.com/folder1
www.domain.com
4

1 回答 1

3

你为什么不使用Uri类?

Dim uri As New Uri("http://www.domain.com/folder1/folder2/folder3/folder4/")

然后你可以得到你需要使用Uri.Host的所有信息Uri.Segments

于 2013-07-14T02:17:28.397 回答