B4J Question Regex array problem

Discussion in 'B4J Questions' started by maleche, Jul 21, 2019.

  1. maleche

    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: Jul 21, 2019
  2. Erel

    Erel Administrator Staff Member Licensed User

    Please use [code]code here...[/code] tags when posting code.
    Try this:
    Code:
    leftvalue = s(0).Trim
    rightvalue = s(
    1).Trim
     
    Didier9 likes this.
  3. Didier9

    Didier9 Active Member Licensed User

    Looks like there is a stray carriage return at the end of string.
     
  4. maleche

    maleche Member Licensed User

    Didier9,
    you are correct!
    in fact, i discovered three and removed them.
    Thank you sir!
     
Loading...
  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