国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PowerShell > 正文

Windows Powershell 訪問數(shù)組

2020-05-30 20:15:19
字體:
供稿:網(wǎng)友

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

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


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

PS C:Powershell> $result=lsPS C:Powershell> $result[0,3,5,12]  Directory: C:PowershellMode        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ù)組增加元素其實相當于創(chuàng)建一個新的數(shù)組,只不過之后會把原來的副本刪除。在當前數(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..4PS C:Powershell> $num1234PS C:Powershell> $num=$num[0..1]+$num[3]PS C:Powershell> $num124
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 蒙自县| 六枝特区| 阜新市| 玛曲县| 鄂伦春自治旗| 宜黄县| 明溪县| 澄江县| 金山区| 武汉市| 尼木县| 乌苏市| 天镇县| 绥宁县| 鸡东县| 太湖县| 察哈| 旬邑县| 民和| 慈利县| 伊川县| 东乌珠穆沁旗| 保山市| 同江市| 台州市| 安龙县| 余姚市| 韶山市| 防城港市| 彩票| 阜新市| 密云县| 克拉玛依市| 万州区| 伊宁市| 岑巩县| 铁岭市| 大名县| 哈尔滨市| 远安县| 宁南县|