I am looking for a way to split a URL, such as http://aaa/bbb/ccc/ddd/eee.
How do I get "ccc"? Of course it is possible to split it, but it is not interesting.
I am looking for a way to split a URL, such as http://aaa/bbb/ccc/ddd/eee.
How do I get "ccc"? Of course it is possible to split it, but it is not interesting.
Uri myuri = new Uri("http://aaa/bbb/ccc/ddd/eee");
String str= myuri.Segments[myuri.Segments.Length-3];
I think this is the most elegant way you can reach by C#.
EDIT:
Actually you can also go with myuri.Segments[2]
here, there give same result. Also note that this code returns "ccc/"
as result, so if you want to get "ccc"
you can go by this(also elegant) way.
String str= myuri.Segments[myuri.Segments.Length-3].TrimEnd('/');