Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 向数组中添加子字符串,并从父字符串中删除该子字符串_Arrays_String_Powershell_Substring - Fatal编程技术网

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。需要阅读更多语法。不知道您可以这样做。