3

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));
0

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

smsCode = str.split("SMS ID: ")[1].split("Job Submitted at: ")[0].replaceAll("\\r|\\n", "");

Comments

0

Try this ?

smsCode = str.split("SMS ID: ")[1].split("\nJob Submitted at: ")[0];

1 Comment

Please include some explanation of what you've fixed or how this works, rather than just posting a code snippet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.