如何删除 System.String 变量的实例?
$Servers = "服务器","本地主机"
我想删除本地主机,有什么想法吗?
您可以设置为$null
Array 条目(您必须知道索引):
$Servers.Set(1, $NULL)
如果您需要的返回值[string]
不是[objtect[]]
[string]$Servers = $Servers[0] # need always knowing the indexs
如果数组计数 > 2,您需要执行以下操作:
$Servers = $servers | ? { $_ -ne "localhost" }
或简而言之
$servers = $servers -ne "localhost"
或者您可以转换为ArrayList
:
[System.Collections.ArrayList]$servers = $servers
$servers.Remove("localhost")