當我傳遞一個多行字符串(至少包含一個回車符)時,'comment'是空的。有沒有解決方案?爲什麼trim()返回一個空字符串,如果它接收到一個多行字符串(包含CR)?
$comment = ($input | where {$_.trim() -ne ""})
當我傳遞一個多行字符串(至少包含一個回車符)時,'comment'是空的。有沒有解決方案?爲什麼trim()返回一個空字符串,如果它接收到一個多行字符串(包含CR)?
$comment = ($input | where {$_.trim() -ne ""})
該行固定的問題:
$comment = @($input)[0]
約
$comment = foreach($line in $input) {$line.trim()}
不應該包含$ input嗎? – moose
當然。我剛剛更新了我的答案。 – gpunktschmitz
如何您的意思是
$comment = ($input -split "`r?`n") | Where-Object { $_.Trim() -ne "" }
什麼這行代碼刪除所有CRLF
您能否顯示重現問題所需的完整示例? – PetSerAl
小心使用'$ input'作爲保留變量。你能向我們展示一個[mcve]嗎? – Matt