Question: I need to parse a URL into an array and was having some difficulties figuring out how to do it properly. It's a bit complicated.

So my URL would be something like this:

<http://sharepoint/webname/libraryname/subfolder1/subfolder2/subfolder3/documentname>

And the results would need to be like so

```
array0 - http://sharepoint
array1 - webname
array2 - libraryname
array3 - subfolder1/subfolder2/subfolder3 
array4 - documentname

```

I would appreciate any guidance.

Answer: 
This works for me:

```
var uri = new Uri(@"http://sharepoint/webname/libraryname/subfolder1/"
    + "subfolder2/subfolder3/documentname");

var segments =
    uri.Segments
        .Select(s => s.EndsWith("/") ? s.Substring(0, s.Length - 1) : s)
        .ToArray();

var array = new []
{
    String.Format("{0}://{1}", uri.Scheme, uri.Host),
    segments[1],
    segments[2],
    String.Join("/", segments.Skip(3).Take(segments.Length - 4)),
    segments[segments.Length - 1],
};

```

I get this result:

![Parsed Uri Array](https://i.stack.imgur.com/TadAi.png)
Use [System.Uri](http://msdn.microsoft.com/en-us/library/system.uri.aspx) to split up the Uri. Then you could use [String.Split](http://msdn.microsoft.com/en-us/library/system.string.split.aspx) on the path.