国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 南开区| 贡山| 府谷县| 乌海市| 秦安县| 策勒县| 天等县| 灌云县| 柞水县| 文成县| 平谷区| 博白县| 酉阳| 江永县| 阿尔山市| 汉源县| 洛隆县| 丁青县| 阳春市| 综艺| 临海市| 吉林市| 竹北市| 汉中市| 江永县| 延长县| 双江| 清苑县| 丘北县| 黄骅市| 辽中县| 北流市| 湖口县| 大荔县| 无棣县| 龙泉市| 西平县| 枣强县| 肃北| 马尔康县| 泽州县|