I'm looking to remove the final '/' character from a string that contains multiple storage paths in it, what is the best way to go about this, I keep getting close but I still can't quite get what I'm looking for, is a loop really the only way?
$Paths = /some/path/1/ /some/path/2/ /some/path/3/
$Paths = $Paths.Remove($Paths.Length - 1)
$Index = $Paths.LastIndexOf('/')
$ID = $Paths.Substring($Index + 1)
I'm currently getting errors like the following:
Exception calling "Remove" with "1" argument(s): "Collection was of a fixed size."
The desired final version of $Paths would be
/some/path/1 /some/path/2 /some/path/3
Any help would be greatly appreciated, I think I may have a process issue as well as a coding issue...
Use the .TrimEnd() method.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With