繁体   English   中英

使用indexof获得第三个斜杠

[英]getting the 3rd slash using indexof

我有一个网址http://www.mysharepointsite.sharepoint.com/sites/test 有什么比获得第三个斜杠及其他更简单的方法来获得/sites/test 如果没有,我如何获得第三个斜线的位置?

是的,您可以使用.NET System.Uri类:

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

这是使用正则表达式的示例:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM