为什么单个元素哈希表在powershell中表现不同?

时间:2016-08-24 09:45:33

标签: powershell

代码示例:

function ToArray([hashtable] $hashTable){
    $ret = @()
    foreach($key in $hashTable.Keys){
        $ret += ("`"" + $key + ":" + $hashTable[$key] + "`"")
    }
    $ret
}


$h1 = @{
    key1 = "value1" # Only one key in this one
}

$h2 = @{
    key2 = "value2"
    key3 = "value3"
}

$h3 = @{
    key4 = "value4"
    key5 = "value5"
}


$test1 = ToArray $h1
$test1 += ToArray $h3

$test2 = ToArray $h2
$test2 += ToArray $h3

Write-Host
Write-Host "TEST 1:" $test1
Write-Host "TEST 2:" $test2

输出:

TEST 1: "key1:value1""key5:value5" "key4:value4"
TEST 2: "key3:value3" "key2:value2" "key5:value5" "key4:value4"

问题: 为什么TEST 1中缺少空格?

0 个答案:

没有答案