tags:

views:

103

answers:

5

Hi,

I am using VB.net Code.

I have got below string

http://localhost:3282/ISS/Training/SearchTrainerData.aspx

Now I want to split above string with "/" as well I want to store value SearchTrainerData.aspx in a variable

In my case

Dim str as String

str = "SearchTrainerData.aspx"

Please give my the code which will split the above string further store it in a variable

Please suggest

Thanks

Best Regards, Sol

+5  A: 

I guess you did not try String.Split ?

leppie
Thanks! Please give me the example code
MKS
@Solution: save everyone the time, including yourself, and just Google for "vb.net string split". There are tons of useful results. It's generally considerate to do some research before posting on SO.
Matt Ball
A: 

use split(). you call it on the string instance, passing in a char array of the delimiters, and it returns to you an array of strings. grab the last element to get your "SearchTrainerData.aspx."

http://msdn.microsoft.com/en-us/library/system.string.split.aspx

Scott M.
+1  A: 

The split function takes characters, which VB.net represents by appending a 'c' to the end of a one-character string.

dim sentence = "http://localhost:3282/ISS/Training/SearchTrainerData.aspx"
dim words = sentence.Split("/"c)
dim lastWord = words(words.length - 1)
Strilanc
Thanks Dear for your help!
MKS
+1  A: 

I guess what you are actually looking for is the System.Uri Class. Which makes all string splitting that you are looking for obsolete.

MSDN Documentation for System.Uri

Uri url = new Uri ("http://...");
String[] parts = url.Segments;
Foxfire
+3  A: 

Your "string" is obviously a URL which means you should 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)

This will also allow you to get all kinds of other interesting information about your "string" without resorting to manual (and error-prone) parsing.

Dan