gpt4 book ai didi

powershell - 如何使字符串段落更易于阅读源代码

转载 作者:行者123 更新时间:2023-12-03 12:35:34 26 4
gpt4 key购买 nike

我正在用 PowerShell 编写脚本,它会显示一条长消息。基本上,我试图弄清楚如何将字符串分成多行,但它仍将显示为单行。

$paragraph = "This is a test to create a single-lined string,
but it doesn't seem to work. I would prefer
to make source code easier to read."

预期输出:

这是一个创建单行字符串的测试,但它似乎不起作用。我更愿意让源代码更易于阅读。

实际输出:

This is a test to create a single-lined string.`
but it doesn't seem to work. I would prefer
to make source code easier to read.

我试过使用反引号,但这会产生相同的结果。有人知道格式化我的代码的正确方法吗?

最佳答案

我会使用 here-string-replace:

$paragraph = @"
This is a test to create a single-lined string.
But it doesn't seem to work. I would prefer
to make source code easier to read.
"@ -replace "`n"," "

关于powershell - 如何使字符串段落更易于阅读源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30292407/

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