copyright 1999 - 2014 by heinz prelle - hannover  - lenbachstraße 42 - www.visual-basic5.de | impressum
'Beispiel: VB .Net - Url ohne Dateinamen zurueckgeben
'
Option Explicit On
Option Strict On

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles Button1.Click
        Dim gu As GetUrl = New GetUrl(Me.TextBox1.Text)
        Dim UrlWithoutFilename As String = gu.UrlWithoutFilename()
        MessageBox.Show(UrlWithoutFilename, "Info")
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles MyBase.Load
        With Me
            .CenterToScreen()
            .TextBox1.Text = "http://www.visual-basic5.de/anzeige.htm"
        End With
    End Sub
End Class

Public Class GetUrl

    Private _url As String

    Public Sub New(ByVal url As String)
        Me._url = url
    End Sub

    Public ReadOnly Property UrlWithoutFilename() As String
        Get
            Return Me.GetUrlWithoutFilename()
        End Get
    End Property

    Private Function GetUrlWithoutFilename() As String
        Dim Position As Integer = Me._url.LastIndexOf("/"c)
        If Position <> -1 AndAlso Position > 7 Then
            Return Me._url.Substring(0, Position)
        End If
        Return Me._url
    End Function

End Class