[英]Populating powershell array from XML
I'm using Powershell 3.0 and Windows Server 2012我正在使用 Powershell 3.0 和 Windows Server 2012
Two arrays populated from an XML file:从 XML 文件填充的两个数组:
$a = @($Data.MessageGroup.Dataset[0].Series[1] | % {$_.Obs} | select TIME_PERIOD, OBS_VALUE)
$b = @($Data.MessageGroup.Dataset[0].Series[3] | % {$_.Obs} | select TIME_PERIOD, OBS_VALUE)
$a
has 680 rows of date values in this format: 2015-09-30
$a
具有以下格式的 680 行日期值: 2015-09-30
$b
has 680 rows of values like: 3051.4
$b
有 680 行值,例如: 3051.4
I can list the elements from each array individually with no issues.我可以单独列出每个数组中的元素,没有问题。 The problem is when I try to join the arrays.
问题是当我尝试加入数组时。
Join the two arrays:加入两个数组:
$c = $a, $b
$c[0]
lists all of the dates; $c[0]
列出所有日期;
$c[1]
lists all of the values. $c[1]
列出所有值。
But when I try to join the two arrays it produces nothing.但是当我尝试加入这两个数组时,它什么也没产生。
$c[0] -join " "
would this work?这行得通吗?
$a = @($Data.MessageGroup.Dataset[0].Series[1] | % {$_.Obs} | select TIME_PERIOD, OBS_VALUE)
$b = @($Data.MessageGroup.Dataset[0].Series[3] | % {$_.Obs} | select TIME_PERIOD, OBS_VALUE)
$i=0
$a | % {$_.TIME_PERIOD + " " + $b[$i++].OBS_VALUE}
For example例如
$a = @(1, 2, 3)
$b = @('a', 'b', 'c')
$i=0
$a | % {"$_ " + $b[$i++]}
Produces生产
1 a
2 b
3 c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.