locked
make array from 2 different arrays RRS feed

  • Question

  • Hi,

    I am sure this is very simple, but when I try

    $a = "test", "test1"

    $b = "test3", "test4"

    $c = $a$b

    It seem to create a string and not an array.  IS there a simepler way or do I need to create a hashtable?


    Alter De Ruine

    Friday, September 7, 2012 2:38 PM

Answers

  • Try this.  

    $c = $a + $b

    PS D:\> $c = $a + $b
    PS D:\> $c
    test
    test1
    test3
    test4

    EDIT: Mjolinor is pretty quick, lucky I use cut and paste instead of make typing.


    Don't forget to mark your posts as answered so they drop off the unanswered post filter. If I've helped you and you want to show your gratitude, just click that green thingy.


    • Edited by Knuckle-Dragger Friday, September 7, 2012 3:44 PM
    • Proposed as answer by Knuckle-Dragger Friday, September 7, 2012 3:44 PM
    • Marked as answer by Yan Li_ Tuesday, September 11, 2012 6:28 AM
    Friday, September 7, 2012 2:41 PM
  • Hashtables are a different animal than an array.

    Array addition is easy:

    $c = $a,$b

    or

    $c = $a + $b


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    • Proposed as answer by Knuckle-Dragger Friday, September 7, 2012 3:45 PM
    • Marked as answer by Yan Li_ Tuesday, September 11, 2012 6:28 AM
    Friday, September 7, 2012 2:43 PM
  • Hashtables are a different animal than an array.

    Array addition is easy:

    $c = $a,$b

    or

    $c = $a + $b


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Your first example, $c = $a,$b creates an array of 2 arrays.  It doesn't combine the arrays into one.

    $c = $a,$b
    $c.count # returns 2
    
    

    Whereas:

    $c = $a + $b
    $c.count # returns 4


    Grant Ward, a.k.a. Bigteddy

    • Marked as answer by Yan Li_ Tuesday, September 11, 2012 6:28 AM
    Friday, September 7, 2012 3:52 PM

All replies

  • Try this.  

    $c = $a + $b

    PS D:\> $c = $a + $b
    PS D:\> $c
    test
    test1
    test3
    test4

    EDIT: Mjolinor is pretty quick, lucky I use cut and paste instead of make typing.


    Don't forget to mark your posts as answered so they drop off the unanswered post filter. If I've helped you and you want to show your gratitude, just click that green thingy.


    • Edited by Knuckle-Dragger Friday, September 7, 2012 3:44 PM
    • Proposed as answer by Knuckle-Dragger Friday, September 7, 2012 3:44 PM
    • Marked as answer by Yan Li_ Tuesday, September 11, 2012 6:28 AM
    Friday, September 7, 2012 2:41 PM
  • Hashtables are a different animal than an array.

    Array addition is easy:

    $c = $a,$b

    or

    $c = $a + $b


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    • Proposed as answer by Knuckle-Dragger Friday, September 7, 2012 3:45 PM
    • Marked as answer by Yan Li_ Tuesday, September 11, 2012 6:28 AM
    Friday, September 7, 2012 2:43 PM
  • Hashtables are a different animal than an array.

    Array addition is easy:

    $c = $a,$b

    or

    $c = $a + $b


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Your first example, $c = $a,$b creates an array of 2 arrays.  It doesn't combine the arrays into one.

    $c = $a,$b
    $c.count # returns 2
    
    

    Whereas:

    $c = $a + $b
    $c.count # returns 4


    Grant Ward, a.k.a. Bigteddy

    • Marked as answer by Yan Li_ Tuesday, September 11, 2012 6:28 AM
    Friday, September 7, 2012 3:52 PM
  • I stand corrected.


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Friday, September 7, 2012 4:03 PM