How to split in VB.NET
I am using VB.NET code.
I have the line below.
http://localhost:3282/ISS/Training/SearchTrainerData.aspx
Now I want to split the above line with "/". I want to store the SearchTrainerData.aspx value in a variable.
In my case
Dim str as String
str = "SearchTrainerData.aspx"
What would be the code that will strip the above string and store it in a variable?
+2
source to share
5 answers
Your "string" is obviously a URL, which means you have to use the System.Uri class .
Dim url As Uri = New Uri("http://localhost:3282/ISS/Training/SearchTrainerData.aspx")
Dim segments As String() = url.Segments
Dim str As String = segments(segments.Length - 1)
It will also allow you to get all sorts of other interesting information about your "string" without having to resort to manual (and error-prone) parsing.
+5
source to share
I assume you are actually looking for System.Uri Class. Which makes all the line splitting you're looking for obsolete.
MSDN Documentation for System.Uri
Uri url = new Uri ("http://...");
String[] parts = url.Segments;
+1
source to share