Remove "/" from url?

Azreal

Member
Joined
Oct 4, 2006
Messages
19
Programming Experience
Beginner
Hello, I have a url of a file as a string, if the url were "h++p://www.vbdotnetforums.com/newthread.php" how would I just get the "newthread.php"?

I have this:

VB.NET:
Dim str As String
str = TextBoxURL.Text
str = str.Substring(str.IndexOf("/"), str.Length - str.IndexOf("/"))

But that only does it for the first "/" in the string.

Any way to make it do work for the last "/" in the string?

Thanks​
 
Use the IO.Path class to manipulate file and folder paths. It works with forward or back slashes:
VB.NET:
MessageBox.Show(IO.Path.GetFileName("http://www.vbdotnetforums.com/newthread.php"))
 
Agreed...

The "Path" class mentioned in the previous post is a very useful class. I had written a lot of functions that do what Path does before I stumbled onto Path.

A lot of what it does could be done by hand, but it's a really nice set of functionality for dealing with directory names and file names.
 
Back
Top