Results 1 to 5 of 5

Thread: Array Join

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    55
    Posts
    1,554
    Rep Power
    174

    Array Add

    small idea for

    Long lCount = Array Add arrayvariable2 Into arrayvariable1


    in example below array sArray1() will thereafter contain all the members of sArray1() and sArray2() together.
    sArray2 is empty then.

    i needed a few times something as this to fast join 2 arrays of strings,


    this only works for dynamic string-array, other types should be easy to realize...
    could also be Add$ for Strings & Add for other types but i guess thinCore will know the type...

    maybe something for new Keyword Into,
    optional switches as Unique or Ascend/Descend thinkeable

    Array Add [Unique] v2 [,Collate Ucase][,Ascend | Descend] Into v1



    Uses "console"
    
    ' --------------------------------------------------------------------
    
    Function Array_Add(ByRef a1() As String, _
                       ByRef a2() As String  _
                        ) As Long
    ' --------------------------------------------------------------------  
      
      ' will move all elements of a2 into a1
      ' a2 will be empty thereafter
      ' returns Ubound of a1
      
      
      If UBound(a2) = 0 Then Return Ubound(a1)
      
      
      ReDim Preserve a1(UBound(a1) + UBound(a2))
      
       Memory_Swap(                                        _
          VarPtr(a1(1)) + 4 * ( UBound(a1) - UBound(a2) ), _
          VarPtr(a2(1)),                                   _
          4 * UBound(a2)                                   )
       
      Function = UBound(a1)
      
    
    End Function  
    
    ' now test it:
    ' --------------------------------------------------------------------
    Function TBMain() 
    ' --------------------------------------------------------------------
      
      Local sArray1(3) As String
      Local sArray2(5) As String
      Local i          As Long
      
      For i = 1 To UBound(sArray1)
        sArray1(i) = "array1(" & TStr$(i) & ")"
      Next
      
      For i = 1 To UBound(sArray2)
        sArray2(i) = "array2(" & TStr$(i) & ")"
      Next
      
      i = array_Add(sArray1, sArray2)
      
      While i                            
        i -= 1
        PrintL sArray1(UBound(sArray1) - i )
      Wend          
      For i = 1 To UBound(sArray2)
        PrintL i, sArray2(i)
      Next
      
      PrintL "key to end"
      WaitKey
    End Function
    
    Last edited by ReneMiner; 25-11-2015 at 18:45. Reason: changed from Join to Add
    I think there are missing some Forum-sections as beta-testing and support

Similar Threads

  1. Help file: JOIN$ sample
    By Petr Schreiber in forum Fixed or cleared errors in help material
    Replies: 2
    Last Post: 23-10-2011, 15:44
  2. JOIN$ with matrix
    By ErosOlmi in forum thinBasic vaporware
    Replies: 0
    Last Post: 03-07-2010, 12:04
  3. Usage of the JOIN$ Keyword
    By Michael Clease in forum Samples for help file
    Replies: 2
    Last Post: 28-05-2007, 13:17

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •