Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Parse text out of URL

Posted on 2008-10-16
3
Medium Priority
?
338 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 1000 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

670 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