我是 PowerShell 的新手,但我想使用它,因为在 Windows 批处理中没有简单的方法来获取字符串的长度。
我需要在 PowerShell 中编写一段代码,遍历 .txt 文件中的每一行并确定该行的字符长度。如果字符长度超过 250,那么......等等。
....etc 部分目前并不重要:)
在 Windows 批处理中我会这样写:
FOR /F %%A IN ("C:\TestFile.txt") DO (
SET LINE=%%A
If LINE > 250 characters then ( ' This line is made up
....etc
)
我该怎么做?
请您参考如下方法:
以下将做你想做的:
$data = Get-Content "C:\TestFile.txt"
foreach($line in $data)
{
if ($line.Length -gt 250) {
Write-Host "A match"
}
}