String 返回不带尾随的字符串'/';性格
我在PowerShell错误检查变量的尾部斜杠并将其删除时遇到问题。例如:String 返回不带尾随的字符串'/';性格,string,url,powershell,String,Url,Powershell,我在PowerShell错误检查变量的尾部斜杠并将其删除时遇到问题。例如: $example1 = 'https://mysite.com/siteone' $example2 = 'https://mysite.com/sitetwo/' 如何检查尾部斜杠?所以,如果我的脚本返回$example1,这很好,脚本将继续。但是,如果它返回$example2,则删除尾随斜杠并使其仅为: https://mysite.com/sitetwo 您可以使用以下命令修剪任何尾随的/字符: 您可以使用以下
$example1 = 'https://mysite.com/siteone'
$example2 = 'https://mysite.com/sitetwo/'
如何检查尾部斜杠?所以,如果我的脚本返回$example1
,这很好,脚本将继续。但是,如果它返回$example2
,则删除尾随斜杠并使其仅为:
https://mysite.com/sitetwo
您可以使用以下命令修剪任何尾随的
/
字符:
您可以使用以下命令修剪任何尾随的
/
字符:
PS > $example1 = 'https://mysite.com/siteone'
PS > $example1.TrimEnd('/')
https://mysite.com/siteone
PS > $example2 = 'https://mysite.com/sitetwo/'
PS > $example2.TrimEnd('/')
https://mysite.com/sitetwo
PS >