欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Windows Powershell 訪問數(shù)組

 更新時(shí)間:2014年09月11日 11:44:58   投稿:hebedich  
本文主要講訴了windows powershell 從數(shù)組中選擇多個(gè)元素,將數(shù)組逆序輸出,給數(shù)組添加和刪除元素,希望對大家理解powershell能有所幫助

數(shù)組的元素可以使用索引尋址,第一個(gè)元素的索引為0,第i個(gè)元素的索引為i-1,最后一個(gè)元素的索引為Count-1,但是Powershell為了使用方便,直接可以將 -1 作為最后的一個(gè)元素的索引。

PS C:Powershell> $books="元素1","元素2","元素3"
PS C:Powershell> $books[0]
元素1
PS C:Powershell> $books[1]
元素2
PS C:Powershell> $books[($book.Count-1)]
元素3
PS C:Powershell> $books[-1]
元素3


從數(shù)組中選擇多個(gè)元素

PS C:Powershell> $result=ls
PS C:Powershell> $result[0,3,5,12]
  Directory: C:Powershell

Mode        LastWriteTime   Length Name
----        -------------   ------ ----
d----    2011/11/23   17:25      ABC
-a---    2011/11/24   20:04   26384 a.txt
-a---    2011/11/24   20:27   12060 alias.ps1
-a---    2011/11/24   17:37    7420 name.html


將數(shù)組逆序輸出

PS C:Powershell> $books="元素1","元素2","元素3"
PS C:Powershell> $books[($books.Count)..0]
元素3
元素2
元素1


給數(shù)組添加和刪除元素

因?yàn)镻owershell數(shù)組在內(nèi)存中是順序存儲(chǔ)的,所以數(shù)組的大小必須是確定的,這樣才方便分配存儲(chǔ)空間,所以給數(shù)組增加元素其實(shí)相當(dāng)于創(chuàng)建一個(gè)新的數(shù)組,只不過之后會(huì)把原來的副本刪除。在當(dāng)前數(shù)組追加元素可以使用“+=”操作符。

PS C:Powershell> $books="元素1","元素2","元素3"
PS C:Powershell> $books+="元素4"
PS C:Powershell> $books
元素1
元素2
元素3
元素4


要?jiǎng)h除第三個(gè)元素可是使用:

PS C:Powershell> $num=1..4
PS C:Powershell> $num
1
2
3
4
PS C:Powershell> $num=$num[0..1]+$num[3]
PS C:Powershell> $num
1
2
4

相關(guān)文章

最新評論