【发布时间】:2021-06-02 19:34:39
【问题描述】:
我想知道如何使用 PowerShell 将带有双引号的字符串输出到单列 CSV。
这是我与此标头一起使用的 csv 文件:
Name | output 1 | output 2 | output 3 |
这是我目前拥有的 PowerShell 代码:
$name = 'Peter Parker'
$out1 = 'testing'
$out2 = -join('"',"21,22,23", '"');
$out3 = 'output'
$text = "$name, $out1, $out2, $out3"
Write-Output $text
$text | Out-File .\test.csv -Encoding ascii -Append
Get-Content -Path .\test.csv
我要找的结果是这样的:
Name | output 1 | output 2 | output 3 |
Peter Parker | testing | "21, 22, 23" | output |
但是我得到了当前代码的这个结果:
Name | output 1 | output 2 | output 3 |
Peter Parker | testing | "21 | 22 | 23" | output |
有没有办法或解决办法来实现我的目标?
谢谢!
【问题讨论】:
标签: string powershell csv file-io double-quotes