B4J Question Regex array problem

maleche

Member
Licensed User
Folks,
please forgive me. i'm not on my programming laptop so i have to type my code.

I have serial data streaming as a comma delimited packet received from

Sub AStream_NewData(buffer() as Byte)
Dim s as String = BytesToString(Buffer,0,Buffer.Length,"UTF8")
ParseValues(s)
End Sub

12,34
44,22
0,46
54,22
56,67
etc...
When the serial data arrives, i send it to a parser:

Sub parseValues(str as String)
Log("DataIn:" & str) <-----------WORKS! shows 12,34
Dim s() as string
Dim leftValue as long
Dim rightValue as long
s=Regex.Split(",",str)
Log("Left:" & s(0) & " Right:" & s(1)) <-----------WORKS! displays correctly!
leftValue = s(0)<-------------WORKS!
rightValue=s(1) <------------this always fails! java.lan.NumberFormatException: For input String: "12 34"
end sub

any help is greatly appreciated!
Thank you in advance!
Doyle
 
Last edited:

Erel

Administrator
Staff member
Licensed User
Please use [code]code here...[/code] tags when posting code.
Try this:
B4X:
leftvalue = s(0).Trim
rightvalue = s(1).Trim
 

maleche

Member
Licensed User
Didier9,
you are correct!
in fact, i discovered three and removed them.
Thank you sir!
 
Top