B4J Question [SOLVED]Extracting from a String

Peter Lewis

Active Member
Licensed User
Longtime User
Hi All

I have a string coming in on a variable which has 2 fields separated by a comma

I have tried this code which I thought should work but does not.

Any ideas please

Thank you

B4X:
        Log(PayLoadStr.IndexOf(","))
            Log(PayLoadStr.SubString2(0,((PayLoadStr.IndexOf(",")-1))))
            Log(PayLoadStr.SubString2((PayLoadStr.IndexOf(",")+1),(PayLoadStr.Length)))
 

Philip Chatzigeorgiadis

Active Member
Licensed User
Longtime User
Tested with this:
B4X:
    Dim PayLoadStr As String ="go,figure"
    Dim commapos As int =PayLoadStr.IndexOf(",")
    Log(commapos)
    Log(PayLoadStr.SubString2(0,commapos))
    Log(PayLoadStr.SubString(commapos+1))

Results:
B4X:
2
go
figure

Note that Substring2(Begin, End) returns characteres from position Begin up to position End-1, i.e. character at position End is not returned.
So: "012345".SubString2(2, 4) returns "23"
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
Tested with this:
B4X:
    Dim PayLoadStr As String ="go,figure"
    Dim commapos As int =PayLoadStr.IndexOf(",")
    Log(commapos)
    Log(PayLoadStr.SubString2(0,commapos))
    Log(PayLoadStr.SubString(commapos+1))

Results:
B4X:
2
go
figure

Note that Substring2(Begin, End) returns characteres from position Begin up to position End-1, i.e. character at position End is not returned.
So: "012345".SubString2(2, 4) returns "23"
Thank you.

I found the the thew first and last incoming string did not have any Commas, they were headers and footers and that is what caused the problem.

Thank you
 
Upvote 0
Top