我想从包含多个存储路径的字符串中删除最后的'/'字符,最好的方法是什么,我一直接近但我仍然无法得到我正在寻找的东西for,是一个循环真的唯一的方法吗?
$Paths = /some/path/1/ /some/path/2/ /some/path/3/
$Paths = $Paths.Remove($Paths.Length - 1)
$Index = $Paths.LastIndexOf('/')
$ID = $Paths.Substring($Index + 1)
Run Code Online (Sandbox Code Playgroud)
我目前收到如下错误:
Exception calling "Remove" with "1" argument(s): "Collection was of a fixed size."
Run Code Online (Sandbox Code Playgroud)
$ Paths的最终版本将是
/some/path/1 /some/path/2 /some/path/3
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激,我想我可能有一个过程问题以及编码问题......
tom*_*ard 11
使用.TrimEnd()方法.
PS > $Paths = '/some/path/1/','/some/path/2/','/some/path/3/'
PS > $Paths
/some/path/1/
/some/path/2/
/some/path/3/
PS > $Paths = $Paths.TrimEnd('/')
PS > $Paths
/some/path/1
/some/path/2
/some/path/3
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14877 次 |
| 最近记录: |