【发布时间】:2013-07-26 20:27:16
【问题描述】:
我不知道该怎么做。我目前的代码如下:
[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
我也不知道为什么。
【问题讨论】:
标签: arrays string powershell substring