B4R Question String join

NoNickName

Member
Licensed User
Since joining strings is not readily available in B4R, at least for ESP, I made a very obvious and short Sub to join two strings. It can be easily extended to join three or more strings if needed.

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Dim bc As ByteConverter
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")

    Dim joined as string = Join("Hello, ", "World!")
    Log(joined)
   
End Sub

public Sub Join(a As String, b As String) As String
   
    Dim cbyte(a.Length+b.Length) As Byte
    bc.ArrayCopy2(a.Getbytes,0,cbyte,0,a.Getbytes.Length)
    bc.ArrayCopy2(b.GetBytes,0,cbyte,a.Getbytes.Length,b.GetBytes.Length)

    Return bc.StringFromBytes(cbyte)

End Sub
 
Top