davetherave
davetherave

Reputation: 1167

getting the 3rd slash using indexof

I have a url http://www.mysharepointsite.sharepoint.com/sites/test. is there any easier what to get the /sites/test than getting the 3rd slash and beyond? and if not how can I get the position of the 3rd slash?

Upvotes: 2

Views: 134

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58981

Yes, you can use the .NET System.Uri Class:

([System.Uri]'http://www.mysharepointsite.sharepoint.com/sites/test').PathAndQuery
# Output: /sites/test

And here is a example using regex:

$site = 'http://www.mysharepointsite.sharepoint.com/sites/test'
$regex = '(?:\/\/).*?(\/.*)'

[regex]::Match($site, $regex).Groups[1].Value
# Output: /sites/test

Upvotes: 3

Related Questions