Temp = QByteArray(TX_Data.toUtf8());
(Function in C i need to replicate)
I need to convert from an ascii string into a utf-8 encoded byte array to satisfy the encoding required by data packets being sent out from an excel spreadsheet to the comm port.
Have tried looking around but can t really find anything suitable - best I found was the code for vba but not compatible with vba - please help
Public Function ConvertStringToUtf8Bytes(ByRef strText As String) As Byte()
Dim objStream As ADODB.Stream
Dim data() As Byte
' init stream
Set objStream = New ADODB.Stream
objStream.Charset = "utf-8"
objStream.Mode = adModeReadWrite
objStream.Type = adTypeText
objStream.Open
' write bytes into stream
objStream.WriteText strText
objStream.Flush
' rewind stream and read text
objStream.Position = 0
objStream.Type = adTypeBinary
objStream.Read 3 ' skip first 3 bytes as this is the utf-8 marker
data = objStream.Read()
' close up and return
objStream.Close
ConvertStringToUtf8Bytes = data
End Function
Bookmarks