gpt4 book ai didi

string - Powershell - $args 去除逗号

转载 作者:行者123 更新时间:2023-12-05 06:45:58 26 4
gpt4 key购买 nike

我正在编写一个脚本来与第 3 方软件交互。

他们以以下格式发送字符串:

sender-ip=10.10.10.10, primary site location=peachtree street, created by=jsmith

然而,当脚本执行时

Write-host $args

这是输出

sender-ip=10.10.10.10 primary site location=peachtree street created by=jsmith

如何保留带有逗号的原始输入字符串?

编辑:

下面是代码片段

$args = $args.ToString()
write-host '$args is' $args

foreach ($i in $args){
$line_array+= $i.split(",")
write-host '$line_array is' $line_array

}

foreach ($j in $line_array){
$multi_array += ,@($j.split("="))
}

foreach ($k in $multi_array){
$my_hash.add($k[0],$k[1])

}


$Sender_IP = $my_hash.Get_Item("sender-ip")

当我用

执行代码时
script.ps1 sender-ip=10.10.10.10, primary site location=peachtree street, created by=jsmith

我明白了

$args is System.Object[]
$line_array is System.Object[]
$Sender_IP is

最佳答案

它将其解释为多个参数。您需要引用整个内容,以便它只知道一个参数:

&{Write-Host $args} sender-ip=10.10.10.10, primary site location=peachtree street, created by=jsmith
&{Write-Host $args} 'sender 10.10.10.10, primary site location=peachtree street, created by=jsmith'

sender-ip=10.10.10.10 primary site location=peachtree street created by=jsmith
sender 10.10.10.10, primary site location=peachtree street, created by=jsmith

关于string - Powershell - $args 去除逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20104165/

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