【发布时间】:2016-08-07 04:20:11
【问题描述】:
我正在尝试使用 PowerShell 在 for 循环中填充迭代器,但我收到一条错误消息。
普通填充效果很好:
$mytext = "Test"
Write-Host $mytext.PadLeft(5, "0")
# Output: 0Test
但是使用迭代器不起作用:
for ($i=1; $i -lt 20; $i++) {
Write-Host $i.PadLeft(2, "0")
}
方法调用失败,因为 [System.Int32] 不包含名为“PadLeft”的方法。
即使我在填充之前将迭代器复制到变量中也不行:
for ($i=1; $i -lt 20; $i++) {
$Iterator = $i
Write-Host $Iterator.PadLeft(2, "0")
}
方法调用失败,因为 [System.Int32] 不包含名为“PadLeft”的方法。
在for 循环中根本不可能使用PadLeft() 吗?
【问题讨论】:
标签: powershell