B4J Question Parsing HEX string

Declan

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

I then parse the required data from the string with:
Code:
        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)":
Code:
An error occurred:
(Line: 122) Dim messageStatus As String = cFrame.SubString2(
java.lang.StringIndexOutOfBoundsException: String index out of range: -12
 
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
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
Thanks, I just overlooked that :(

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

Similar Threads

Replies
2
Views
3K
  • Article Article
Android Code Snippet [B4X] Hex string to number
Replies
0
Views
6K
  • Locked
  • Article Article
Replies
6
Views
10K
Replies
6
Views
4K
  • Question Question
B4J Question ParseHexToFloat
Replies
3
Views
3K
Back
Top