gpt4 book ai didi

powershell - 如何使用 PowerShell 和 System.IO.StreamWriter 编写 Linux 换行符

转载 作者:行者123 更新时间:2023-12-04 00:53:49 24 4
gpt4 key购买 nike

我需要使用 System.IO.StreamWriter 从 PowerShell 编写 Linux 风格的换行符(出于性能原因):

$writer = New-Object System.IO.StreamWriter "path\to\file"
$writer.WriteLine("{0};{1}", $timestamp, $value)

我接近解决方案:System.IO.StreamWriter 有一个 NewLine 属性,但它没有按预期工作:

$writer.NewLine = "\n"
$writer.WriteLine("{0};{1}", "23/12/2014", 45000)
$writer.WriteLine("{0};{1}", "24/12/2014", 54000)

产生:

23/12/2014;45000\n24/12/2014;54000\n...

最佳答案

在 PowerShell 双引号字符串中,使用反引号作为转义字符(不是反斜杠)。

尝试

$writer.NewLine = "`n"

关于powershell - 如何使用 PowerShell 和 System.IO.StreamWriter 编写 Linux 换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26801975/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com