gpt4 book ai didi

powershell - 在 PowerShell 中替换子字符串

转载 作者:行者123 更新时间:2023-12-02 23:46:05 26 4
gpt4 key购买 nike

我有一个 -content- 形式的字符串,我想将其替换为 &content&。如何在 PowerShell 中使用替换来做到这一点?

最佳答案

PowerShell 字符串只是 .NET 字符串,因此您可以:

PS> $x = '-foo-'
PS> $x.Replace('-', '&')
&foo&

...或:

PS> $x = '-foo-'
PS> $x.Replace('-foo-', '&bar&')
&bar&

显然,如果你想保留结果,请将其分配给另一个变量:

PS> $y = $x.Replace($search, $replace)

关于powershell - 在 PowerShell 中替换子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14912948/

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