I have two Byte Array (or more) and I should merge it into one Dim A() As Byte = Array As Byte(23,45,67) Dim B() As Byte = Array As Byte(223,1,70) Dim c() As Byte c= A & B ' Come si può fare? ' I want to get it: C = (23,45,67,223,1,70) This operation I have to repeat it for several Array...
www.b4x.com
B4X:
Public Sub Merge (array1() As String, array2() As String) As String()
Dim BC As ByteConverter
Dim array3(array1.Length + array2.Length) As String
BC.ArrayCopy(array1, 0, array3, 0, array1.Length)
BC.ArrayCopy(array2, 0, array3, array1.Length, array2.Length)
Return array3
End Sub
In B4i, I am getting errors at line #4 and #5 when calling BC.ArrayCopy:
B4X:
Cannot cast type: {Type=String,Rank=1, RemoteObject=True} to: {Type=Byte,Rank=1, RemoteObject=True}
For B4i, I can't use the above code snippet but to copy the items one by one?
Since B4I byteconverter's arrayCopy seems to be limited to bytes, this can be a nice replacement (only tested in debug mode)
B4X:
Dim array1() As String = Array As String("1","2","3","4","5")
Dim array2() As String = Array As String("6","7","8")
Dim array3() As String
array3.As(List).AddAll(array1.As(List))
array3.As(List).AddAll(array2.As(List))
For k=0 To array3.Length-1
Log(array3(k)) '<-- 1 2 3 4 5 6 7 8
Next
Yes.
Have you tested with non-integer items in the list/arrays?
Recently I am updating a B4X library (MiniORMUtils) which required array of String as parameter in Execute method.
I will test it when I have time.
Thanks.
Public Sub Merge (array1() As String, array2() As String) As String()
Dim res(array1.Length + array2.Length) As String
For i = 0 To array1.Length - 1
res(i) = array1(i)
Next
For i = 0 To array2.Length - 1
res(i + array1.Length) = array2(i)
Next
Return res
End Sub
Public Sub Merge (array1() As String, array2() As String) As String()
Dim res(array1.Length + array2.Length) As String
For i = 0 To array1.Length - 1
res(i) = array1(i)
Next
For i = 0 To array2.Length - 1
res(i + array1.Length) = array2(i)
Next
Return res
End Sub
MiniORMUtils Version: 3.30 This library can be use for creating db schema and performing CRUD operations. It is suitable for Web API Template or any database system. Currently it supports SQLite and MySQL (B4J). Project Template: [B4X] [Project Template] MiniORM Examples: Create...
www.b4x.com
B4X:
#If B4A or B4i
Public Sub AddParameters (Params() As String)
'DBParameters = Merge(DBParameters, Params)
If Params.Length = 0 Then Return
If DBParameters.Length > 0 Then
Dim NewArray(DBParameters.Length + Params.Length) As String
For i = 0 To DBParameters.Length - 1
NewArray(i) = DBParameters(i)
Next
For i = 0 To Params.Length - 1
NewArray(DBParameters.Length + i) = Params(i)
Next
DBParameters = NewArray
Else
DBParameters = Params
End If
End Sub
#Else
Public Sub AddParameters (Params As List)
DBParameters.AddAll(Params)
End Sub
#End If
Thanks for the suggestion.
I have tried to use a List but it seems B4i doesn't like it.
If I remember correctly, it is DBUtils.ExecuteMap(DBSQL, DBStatement, DBParameters) in B4A or B4i that expect a String array in 3rd argument. In B4J, I am using a List which is more convenient.
I welcome anyone to fork my repo and improve MiniORMutils library.