I have a String which goes like this in my logcat
24:John Smith
Contact Number: 999999999
Customer Address: Texas 47
Store: Subway
Time Frame: 4:00pm - 5:00pm
Request: One sandwhich
SMS ID: 2493
Job Submitted at: 2015年03月14日 18:27:45
And I assigned the SMS ID to a String variable smsCode with the following code:
smsCode = str.split("SMS ID: ")[1].split("Job Submitted at: ")[0];
And in my logcat it shows that smsCode is equals to 2493
However when I pass the variable to PHP it doesn't work. It could be due to the spacing. I have used smsCode.trim() and it doesn't work as well.
It works if I put in the real value without variable:
nameValuePairs.add(new BasicNameValuePair("smsCode", "2493"));
It doesn't when its the variable as below.
nameValuePairs.add(new BasicNameValuePair("smsCode", smsCode));
3 Answers 3
The issue is that in your first example where you use the hard coded value, you are infact passing only that text value.
In the second example, using the variable smsCode does not actually contain the value you think it does, following the previous lines of text - smsCode at this point actually has a text value of 2493\n.
Try and do as already suggested, and prepend a \n to your second split to remove that extra newline character.
Comments
Try this:
smsCode = str.split("SMS ID: ")[1].split("Job Submitted at: ")[0].replaceAll("\\r|\\n", "");
Comments
Try this ?
smsCode = str.split("SMS ID: ")[1].split("\nJob Submitted at: ")[0];