Search code examples
c#.netbase-class-library

Is there a built-in function to get the "ghi" from www.abc.com/def/ghi in the BCL?


Is there a built-in function to get the ghi from www.abc.com/def/ghi in the BCL? I know it is dead easy to create a small method that does just that, but I wonder if there is something already that will take care of it for me.

If it could also get me def and abc that'd be a bonus.


Solution

  • You could pass the url to the Uri class constructor and inspect the Segments property. Or if the string you have could be invalid you could first try parsing it using the TryCreate method.