Android Code Snippet [B4X] Join arrays of bytes

Discussion in 'Code Snippets' started by Erel, Dec 3, 2017.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Input = A list (or array of objects) with one or more arrays of bytes.
    Output = An array of bytes with the input data.

    Sub JoinBytes(ListOfArraysOfBytes As ListAs Byte()
    Dim size As Int
    For Each b() As Byte In ListOfArraysOfBytes
         size = size + b.Length
    Dim result(size) As Byte
    Dim index As Int
    Dim bc As ByteConverter 'ByteConverter library
       For Each b() As Byte In ListOfArraysOfBytes
    0, result, index, b.Length)
         index = index + b.Length
    Return result
    End Sub
    Usage example:
    Dim b() As Byte = JoinBytes(Array("abcde".GetBytes("utf8"), "fghij".GetBytes("utf8"), _
    Log(BytesToString(b, 0, b.Length, "utf8"))
    Depends on ByteConverter library (iRandomAccessFile in B4i).
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice