Hello, how can I put a converted string in a Astream byte array?
B4X:
Dim dati() As Byte
dati = Array As Byte(0x01, 0x10, 0x01, 0x0A, 0x00, 0x01, 0x02, 0x01, 0xFF, 0xF7, 0xEA)
AStreams.Write(dati)
This example works fine.
But I want something like this:
B4X:
Dim dati() As Byte
Dim testo as string
testo = "0x01, 0x10, 0x01, 0x0A, 0x00, 0x01, 0x02, 0x01, 0xFF, 0xF7, 0xEA"
dati = Array As Byte(testo)
AStreams.Write(dati)
How can I do it?
I have tried with the second example I have wrote, but I receive: "An Error has occured in sub: java.lang. NumberFormatException: Invalid double: " " Continue?
1. You will need to split the string with Regex.Split.
2. Trim each of the strings and remove the first two characters.
3. Call Bit.ParseInt to parse the hex number.