最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Windows Powershell 訪問(wèn)數(shù)組

 更新時(shí)間:2014年09月11日 11:44:58   投稿:hebedich  
本文主要講訴了windows powershell 從數(shù)組中選擇多個(gè)元素,將數(shù)組逆序輸出,給數(shù)組添加和刪除元素,希望對(duì)大家理解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ù)組,只不過(guò)之后會(huì)把原來(lái)的副本刪除。在當(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)文章

最新評(píng)論

同德县| 安平县| 镇安县| 泰和县| 攀枝花市| 白山市| 新余市| 万山特区| 米脂县| 和政县| 利川市| 肥西县| 云和县| 汾西县| 怀安县| 玉树县| 吉首市| 双城市| 泽普县| 徐闻县| 江源县| 景谷| 南木林县| 疏勒县| 广汉市| 怀来县| 湘阴县| 台北市| 荔浦县| 平乡县| 浮梁县| 攀枝花市| 山东省| 麦盖提县| 潢川县| 日喀则市| 明光市| 金昌市| 桐城市| 汉中市| 内黄县|