Solved

Parse text out of URL

Posted on 2008-10-16
3
315 Views
Last Modified: 2013-11-07
I need to be able to grab a part of a URL and place in a textbox.
I want to grab the last part of the URL from a textbox, and place in another textbox. I need everything from the end of the url, to the last /.
Example:
textbox1.text = "http://www.site.com/stuff/stuffz/thing.exe
textbox2.text = "thing.exe"

I have tried using the function and code below, but it doesn't work the way I need it.

It just returns the URL without the / 's.

Any help is appreciated.
Public Function midReturn(ByVal first As String, ByVal last As String, ByVal total As String) As String

        If last.Length < 1 Then

            midReturn = total.Substring(total.IndexOf(first))

        End If

        If first.Length < 1 Then

            midReturn = total.Substring(0, (total.IndexOf(last)))

        End If

        Try

            midReturn = ((total.Substring(total.IndexOf(first), (total.IndexOf(last) - total.IndexOf(first)))).Replace(first, "")).Replace(last, "")

        Catch ArgumentOutOfRangeException As Exception

        End Try

    End Function
 

    Private Sub btnClip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClip.Click
 

        txtName.Text = midReturn("/", "", txtLink.Text)
 

    End Sub

Open in new window

0
Comment
Question by:zerogeek
3 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 250 total points
ID: 22729107
Hello zerogeek,

txtName.Text = txtLink.Text.Substring(txtLink.Text.LastIndexOf("/")+1)

Should do it.

Regards,

TimCottee
0
 

Author Comment

by:zerogeek
ID: 22729153
Worked Perfect! Thanks!
0
 
LVL 2

Expert Comment

by:JasonChandler
ID: 22729177
This should do what you need.
Set up a page with to textboxes on it and please test.
I have set this up in the Page_Load Event however you put this in a function.

Hope this helps
Jason
Code behind

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim s As String = "http://www.site.com/stuff/stuffz/thing.exe"

        Dim lengthOfFullString As Integer = s.Length

        Dim i As Integer = s.LastIndexOf("/")

        Dim texbox1Text As String = s.Remove(i) ' If you want the / at the end then just add + "/"

        Dim texbox2Text As String = s.Substring(i)

        Me.TextBox1.Text = texbox1Text

        Me.TextBox2.Text = texbox2Text

    End Sub
 

ASPX PAGE

    <div>

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />

        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />

    </div>

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now