Arrays 向数组中添加子字符串,并从父字符串中删除该子字符串
我不知道怎么做。我目前的代码如下:Arrays 向数组中添加子字符串,并从父字符串中删除该子字符串,arrays,string,powershell,substring,Arrays,String,Powershell,Substring,我不知道怎么做。我目前的代码如下: [string]$strTest = Read-Host "Please input an IP host address in full dotted decimal.`n(Example: 192.168.004.214)" [array]$arrTest = 0 $str = $strTest $fs = "." $index = $str.indexof($fs) $count = 1 do{ $chunk = $str.substring(0
[string]$strTest = Read-Host "Please input an IP host address in full dotted decimal.`n(Example: 192.168.004.214)"
[array]$arrTest = 0
$str = $strTest
$fs = "."
$index = $str.indexof($fs)
$count = 1
do{
$chunk = $str.substring(0,$index)
$arrTest += $chunk
$count++
$str = $str -replace ($chunk + ".", "")
}
until($count -eq 4)
$arrTest
我想让它给我一个数组,它填充了IP地址的每个八位组,但我得到了一个奇怪的结果。在ISE中运行此命令可以让我:
0
123
123
123
我也不知道为什么。如果你想要一个包含八位字节的数组,只需拆分字符串:
$a = $str.Split('.')
你把括号搞错了
$str=$str-replace($chunk+),“
该死的,谢谢!我实际上一直在学习powershell。需要阅读更多语法。不知道您可以这样做。