P Peter Lewis Well-Known Member Licensed User Longtime User Apr 22, 2020 #1 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: Copy Log(PayLoadStr.IndexOf(",")) Log(PayLoadStr.SubString2(0,((PayLoadStr.IndexOf(",")-1)))) Log(PayLoadStr.SubString2((PayLoadStr.IndexOf(",")+1),(PayLoadStr.Length)))
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: Copy 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 Apr 22, 2020 #2 Tested with this: B4X: Copy 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: Copy 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
Tested with this: B4X: Copy 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: Copy 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"
P Peter Lewis Well-Known Member Licensed User Longtime User Apr 22, 2020 #3 Philip Chatzigeorgiadis said: Tested with this: B4X: Copy 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: Copy 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" Click to expand... 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
Philip Chatzigeorgiadis said: Tested with this: B4X: Copy 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: Copy 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" Click to expand... 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