gpt4 book ai didi

powershell - 将逗号分隔的字符串转换为列表

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

我有以下powershell代码:

$Credentials = 'Credentials: myacct1,myacct2'

$runtimes = $Credentials -match "Credentials: (?<content>.*)"
$runtimeList = $matches['content']
Foreach ($runtime in $runtimeList)
{
Write-Host $runtime
}

那只是返回 myacct1,myacct2我想要它遍历列表的地方
myacct1
myacct2

最佳答案

我敢肯定,您只需要使用,将匹配的字符串按String.Split()拆分即可。

$Credentials = 'Credentials: myacct1,myacct2'

$runtimes = $Credentials -match "Credentials: (?<content>.*)"
$runtimeList = $matches['content'].Split(",")
Foreach ($runtime in $runtimeList)
{
Write-Host $runtime
}

# Output:
# myacct1
# myacct2

关于powershell - 将逗号分隔的字符串转换为列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52449006/

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