954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Extracting parts of a URL with System.Uri

I reworked my code into a way that was simpler.

I have a URL in the following format: "http://sub.domain.tld/path/to/page"
I need to extract 'path' and 'page' and discard the rest of the URL.

I know about the System.Uri class and with Uri.AbsolutePath I can get "/path/to/page/". I need a way of splitting that into 'path' and 'page'. I can currently do it with the String.SubString / String.IndexOf / String.LastIndexOf methods but that requires bounds checking and checking the return values of each method to be safe. Is there a simpler and more robust way?

chrisname
Light Poster
26 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: