B4J Question Parsing HEX string

Declan

Well-Known Member
Licensed User
Longtime User
I receive the following string frm Sigfox Callback:
B4X:
00786d653fb7da0123000000

I then parse the required data from the string with:
B4X:
        Log("Got Sense01")
        Dim ProductType As String = cFrame.SubString2(0,2)
        Dim beaconmac As String = cFrame.SubString2(2,14)
        Dim messageStatus As String = cFrame.SubString2(14,2)
        Dim BattLevel As String = cFrame.SubString2(16,2)

However, I receive the following error at line "Dim messageStatus As String = cFrame.SubString2(14,2)":
B4X:
An error occurred:
(Line: 122) Dim messageStatus As String = cFrame.SubString2(
java.lang.StringIndexOutOfBoundsException: String index out of range: -12
 

DonManfred

Expert
Licensed User
Longtime User
SubString2 (BeginIndex As Int, EndIndex As Int) As String
Returns a new string which is a substring of the original string.
The new string will include the character at BeginIndex and will extend to the character at EndIndex, not including the last character.

The second value is NOT A LENGTH!
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
SubString2 (BeginIndex As Int, EndIndex As Int) As String
Returns a new string which is a substring of the original string.
The new string will include the character at BeginIndex and will extend to the character at EndIndex, not including the last character.

The second value is NOT A LENGTH!

@DonManfred - Many thanks I forgot that
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
Thanks, I just overlooked that :(

How do I covert:
B4X:
Dim BattLevel As String = cFrame.SubString2(16,2)
to the Decimal Value of the BattLevel String?
 
Upvote 0

Similar Threads

Replies
0
Views
3K
  • Locked
  • Article
Android Code Snippet [B4X] HexToColor and ColorToHex
Replies
6
Views
5K
Replies
3
Views
979
Top