What is the idiomatic way to slice an array relative to both of its ends?

前端 未结 7 1443
梦如初夏
梦如初夏 2021-02-06 20:35

Powershell\'s array notation has rather bizarre, albeit documented, behavior for slicing the end of arrays. This section from the official documentation sums up the bizarreness

7条回答
  •  渐次进展
    2021-02-06 21:04

    I believe this is the right way to do it. all other methods require more code.

    $a[1..($a.Count-1)]
    

    Also, if array is converted to string it becomes easy to get data as below:

    $a = 0,1,2,3
    [string]::Concat($a).Substring(1)
    

提交回复
热议问题