Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.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
Powershell 我应该将子字符串的数组下标的开头和结尾连接起来吗_Powershell - Fatal编程技术网

Powershell 我应该将子字符串的数组下标的开头和结尾连接起来吗

Powershell 我应该将子字符串的数组下标的开头和结尾连接起来吗,powershell,Powershell,我在读50个州不同长度的驾照号码。我需要将最后4位数字更改为9 如何在数组中获取下标的开始部分,然后将它们连接在一起?如果您在文件中的每行都有一个单独的驾驶执照号码,那么这将起作用: $getRead = @($readFile) for($i = 0; $i -lt getRead.length; $i++){ $getEnd = $readFile.substring(readFile[$i].length - 1, 4) $getStart = $readFile.sub

我在读50个州不同长度的驾照号码。我需要将最后4位数字更改为
9

如何在数组中获取下标的开始部分,然后将它们连接在一起?

如果您在文件中的每行都有一个单独的驾驶执照号码,那么这将起作用:

$getRead = @($readFile)

for($i = 0; $i -lt getRead.length; $i++){
    $getEnd = $readFile.substring(readFile[$i].length - 1, 4)
    $getStart = $readFile.substring(readFile[$i].length 1, $getEnd)

    #$findMatchREGEX = "[0-8]"
    #$replaceWithREGEX = "9"

    #$newNum = $readFile -replace $findMatchREGEX,$replaceWithREGEX

}
`$getStart=$line.substring(0,$line.Length-5)`ohhh好的,这很有意义。非常感谢。
$readFile = "c:/path/file"
$getRead = gc $readFile

foreach ($line in $getRead){
    $getStart = $line.substring(0, $line.Length - 5)
    $resultWithNines = $getStart + "9999"
    echo $resultWithNines 
}