![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| Guest | output multiple arrays to file trying to find the best way to take 3 arrays and output them to a file so that each line would be $a1[$i], $a2[$i], $a3[$i] im sure this is easy, but i keep tripping over it. Thanks Justin |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: output multiple arrays to file Hi Justin, This assumes that your arrays all contain the same number of elements. $a = 1..10 ; $b = 11..20 ; $c = 21..30 foreach ( $i in (0..$a.count) ) { Add-Content -path "arraytest.txt" ` -value "$($a[$i])`r`n$($b[$i])`r`n$($c[$i])" } Just one way though, bet there are dozens of other|better ways. Cheers, Stuart |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: output multiple arrays to file Ahem. Or even:- $a = 1..10 ; $b = 11..20 ; $c = 21..30 foreach ( $i in (0..($a.count -1)) ) { Add-Content -path "arraytest.txt" ` -value "$($a[$i])`r`n$($b[$i])`r`n$($c[$i])" } Cheers, Stuart |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: output multiple arrays to file It occurred to me that there must be a simple way to combine two arrays. But I couldn't think of it, so wrote this very simple function that might be of use to someone, somewhere, someday. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function combine-arrays ( $array1,$array2 ) { if ($array1.count -ne $array2.count) { "Arrays are different sizes" ; exit } $newarray = @() $c = $array1.count for ( $i = 0; $i -le $c; $i++ ) { $newarray += $array1[$i] $newarray += $array2[$i] } return $newarray } $a = 1..10 $b = 11..20 combine-arrays $a $b ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Hope it helps, Stuart |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: output multiple arrays to file Thanks! This was what I was looking for. "Kryten" <Kryten68@xxxxxx> wrote in message news:27853c17-c198-4a9a-a885-3a28a2570705@xxxxxx Quote: > Ahem. Or even:- > > $a = 1..10 ; $b = 11..20 ; $c = 21..30 > foreach ( $i in (0..($a.count -1)) ) { > Add-Content -path "arraytest.txt" ` > -value "$($a[$i])`r`n$($b[$i])`r`n$($c[$i])" > > } > > Cheers, > Stuart > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Can Vista Ultimate output to multiple audio devices? | Vista hardware & devices | |||
| Print to File/Output file name issue | Vista print fax & scan | |||
| Problem with multiple audio/video sound output | Sound & Audio | |||
| Output to multiple devices similtaneously? | Sound & Audio | |||
| output format with multiple commands | PowerShell | |||