0
我收到以下代碼的錯誤。我試圖在超過180個字符的文本文件中將行分析並將它們解析爲新行。我不得不採取的第一個22個字符,並把它從第二部分,因爲它其中包含的需要就行inital數據:子字符碼錯誤 - Powershell
$data = get-content "C:\TestFile.txt"
$strAcct= @()
$strPart1= @()
$strPart2= @()
$strLength= @()
foreach($line in $data)
{
if ($line.length -gt 181)
{ $strLength = $line.length
$strAcct += $line.substring(0,22)
$strPart1 += $line.substring(0,180)
$strPart2 += $line.substring(181,$strLength)
Add-Content "C:\TestFile-Output.txt" $strPart1
Add-Content "C:\TestFile-Output.txt" $strAcct $strPart2
}
Else {
Add-Content "C:\TestFile-Output.txt" $line
}
}
我想工作,謝謝。我收到一個炸彈:添加內容「C:\ TestFile-Output.txt」$ strAcct $ strPart2 如何打印$ strAcct AND $ strPart2 – Noesis
添加內容「C:\\ TestFile-Output。 txt「($ strAcct + $ strPart2) –
它將strPart2放在新行上,而不是與$ strAcct同一行。有任何想法嗎? – Noesis