佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > Windows Powershell 訪問數(shù)組

Windows Powershell 訪問數(shù)組

熱門標(biāo)簽:鐵路電話系統(tǒng) 呼叫中心市場需求 Linux服務(wù)器 百度競價排名 AI電銷 服務(wù)外包 網(wǎng)站排名優(yōu)化 地方門戶網(wǎng)站

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

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ù)組中選擇多個元素

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ù)組添加和刪除元素

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

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


要刪除第三個元素可是使用:

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
您可能感興趣的文章:
  • Windows Powershell 創(chuàng)建數(shù)組
  • Windows Powershell 復(fù)制數(shù)組
  • Windows Powershell強(qiáng)類型數(shù)組
  • Windows Powershell使用哈希表
  • Windows Powershell使用管道
  • Windows Powershell對象轉(zhuǎn)換成文本

標(biāo)簽:崇左 湘潭 衡水 銅川 仙桃 黃山 湖南 蘭州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Windows Powershell 訪問數(shù)組》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    武宁县| 湖南省| 涞源县| 溆浦县| 万载县| 巴彦县| 固安县| 蕉岭县| 抚远县| 新河县| 盐亭县| 穆棱市| 邵阳市| 云林县| 左云县| 平乐县| 桃江县| 稻城县| 轮台县| 曲沃县| 定襄县| 玉树县| 波密县| 台中县| 巫山县| 咸宁市| 交城县| 普宁市| 桐城市| 阜平县| 济源市| 镇宁| 南召县| 盘山县| 宜宾县| 灯塔市| 古浪县| 拉萨市| 建昌县| 浙江省| 金乡县|