Merging arrays

Discussion in 'Microsoft VB .NET' started by John, May 7, 2007.

  1. John

    John Guest

    Hi

    Is there a way to merge two or more single dimension string arrays into a
    single, single dimension string array?

    Thanks

    Regards
     
    John, May 7, 2007
    #1
    1. Advertisements

  2. John

    Lloyd Sheen Guest

    "John" <> wrote in message
    news:...
    > Hi
    >
    > Is there a way to merge two or more single dimension string arrays into a
    > single, single dimension string array?
    >
    > Thanks
    >
    > Regards
    >
    >


    There is no "merge" functionality but you could just append the arrays and
    the sort the array in the "merged" order.

    Hope this helps.

    Lloyd Sheen
     
    Lloyd Sheen, May 7, 2007
    #2
    1. Advertisements

  3. Or in addition to lloyd merge as it is forever done by looping through the
    two ore more files.

    Be aware to make it first arraylist in both situations otherwise it will
    probably freeze up your computer.

    Cor

    "John" <> schreef in bericht
    news:...
    > Hi
    >
    > Is there a way to merge two or more single dimension string arrays into a
    > single, single dimension string array?
    >
    > Thanks
    >
    > Regards
    >
    >
     
    Cor Ligthert [MVP], May 7, 2007
    #3
  4. John wrote:
    > Hi
    >
    > Is there a way to merge two or more single dimension string arrays into a
    > single, single dimension string array?
    >
    > Thanks
    >
    > Regards
    >


    Create a new array with the combined size of the arrays, and copy the
    elements from the arrays:

    Dim newArray As String() = New String(oldArray1.Length + oldArray2.Length)
    oldArray1.CopyTo(newArray, 0)
    oldArray2.CopyTo(newArray, oldArray1.Length)

    --
    Göran Andersson
    _____
    http://www.guffa.com
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, May 7, 2007
    #4
  5. >Create a new array with the combined size of the arrays, and copy the
    >elements from the arrays:
    >
    >Dim newArray As String() = New String(oldArray1.Length + oldArray2.Length)


    I'm sure you meant

    .... New String(oldArray1.Length + oldArray2.Length - 1) {}


    Mattias

    --
    Mattias Sjögren [C# MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.
     
    Mattias Sjögren, May 7, 2007
    #5
  6. Mattias Sjögren wrote:
    >> Create a new array with the combined size of the arrays, and copy the
    >> elements from the arrays:
    >>
    >> Dim newArray As String() = New String(oldArray1.Length + oldArray2.Length)

    >
    > I'm sure you meant
    >
    > ... New String(oldArray1.Length + oldArray2.Length - 1) {}
    >
    >
    > Mattias
    >


    Yes. I don't program any VB myself nowadays. I thought that when
    creating an array this way, it would use the size.

    --
    Göran Andersson
    _____
    http://www.guffa.com
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, May 8, 2007
    #6
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Eaden

    arrays in vb.net !

    Tim Eaden, Jul 9, 2003, in forum: Microsoft VB .NET
    Replies:
    3
    Views:
    516
    Armin Zingler
    Jul 9, 2003
  2. Armin Zingler

    Re: Control Arrays

    Armin Zingler, Jul 22, 2003, in forum: Microsoft VB .NET
    Replies:
    1
    Views:
    489
    Mr. B
    Jul 22, 2003
  3. Mr. B

    Q: How to Work with Control Arrays?

    Mr. B, Jul 26, 2003, in forum: Microsoft VB .NET
    Replies:
    3
    Views:
    449
    Mr. B
    Jul 26, 2003
  4. loleta

    Arrays

    loleta, Aug 25, 2003, in forum: Microsoft VB .NET
    Replies:
    2
    Views:
    415
  5. Gary Owsiany

    Re: Sorting arrays

    Gary Owsiany, Aug 27, 2003, in forum: Microsoft VB .NET
    Replies:
    10
    Views:
    266
    Gary Owsiany
    Aug 30, 2003
Loading...

Share This Page