我正在输出一些从文件中提取的文本行,并且当我在 $strAcct 之后输出此部分时,正在添加回车:
Add-Content "C:\TestFile-Output.txt" ($strAcct+$strPart2)
所以基本上文件中打印的是 $strAcct回车/换行$strPart2
这是我的所有代码:
#Setting Variables
$data = get-content "C:\TestFile.txt"
$strAcct= @()
$strPart1= @()
$strPart2= @()
$strLength= @()
#For each line of text in variable $data, do the following
foreach($line in $data)
{
#reseting variables for each time the FOR loop repeats
$strAcct= @()
$strPart1= @()
$strPart2= @()
$strLength= @()
#We're saying that if the line of text is over 180 characters, were going to split it up into two different lines so MEDITECH can accept this note files
if ( $line.length -gt 180)
{ $strLength = $line.length
$strAcct += $line.substring(0,22)
$strPart1 += $line.substring(0,180)
$strPart2 += $line.substring(181)
#Create first and second line in text file for the string of text that was over 180 characters
Add-Content "C:\TestFile-Output.txt" $strPart1
Add-Content "C:\TestFile-Output.txt" ($strAcct+$strPart2)
}
#If our line of text wasn't over 180 characters, just print it as is
Else {
Add-Content "C:\TestFile-Output.txt" $line
}
}