数组中PowerShell不会被写成数组 [英] Array in Powershell WON'T be written as an Array
问题描述
不管我怎么写这个剧本,Powershel不会因为它应该,它打印一个单一的线阵列写我的数组。
No matter how I write this script, Powershel will not write my array as it should, it prints a single line array.
PS C:\Windows\system32> $matriz = @(
(1,2,3,4),
(5,6,7,8)
)
Write-Host $matriz
1 2 3 4 5 6 7 8
无论是这样的:
PS C:\Windows\system32> $matriz = ,@((1,2,3,4),
(5,6,7,8))
Write-Host $matriz
1 2 3 4 5 6 7 8
如何打印这是一个真正的2维矩阵?结果
而且......我想填充获取随机
此相同的数组,但它显示了以下错误:无法添加的号码,你在哪里希望(即matriz [0,1]),因为它不支持分数
< - 而不是真正的消息,但你们不会明白葡萄牙语:/
How do I print this as a real 2-dimension matrix?
And... I'm trying to populate this same array with Get-Random
, but it shows the following error: Failed add the number where you want (i.e. matriz [0,1]) because it doesn't support fractions
<- Not the real message but you guys won't understand portuguese :/
*更新:结果
我希望它可以打印,这一点:结果
1 2 3 4结果
5 6 7 8结果
原因单行事情不会帮我看看我的基质是正确的,作为一个单一的线我永远不会知道什么是数组的对角线。
*Update:
I want it to be printed as this:
1 2 3 4
5 6 7 8
'Cause the single line thing won't help me to see if my matrix is correct, as a single line I will never know what is in the array's diagonal line.
推荐答案
所以,当你的输出数组,PowerShell的默认输出一个新行每个数组项。这里得到什么,我认为你想一个办法:
So when you output an array, powershell by default outputs each array item on a new line. Here is one way to get what I think you want:
Write-Host $matriz | %{$_ -join ' '}
所以,你告诉它继续前进,使用外部阵列的新线,但每个里面阵列加入他们使用的空间。
So you tell it to go ahead and use the new line for the outside array, but for each of the inside arrays join them using spaces.
这篇关于数组中PowerShell不会被写成数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!