-2

i have this below response from a HTTP Get request

RESPONSE=You are about to purchase abcd package for 20 usd. Charge :1usd&encoding=0&SessionOp=end

I'm trying to get only "You are about to purchase abcd package for 20 usd. Charge :1usd" to a string in java so that i can display it to the customer, but i'm not sure how.

Any help would be appreciated. thank you

  • 1
    Possible duplicate of [How to split a string in Java](https://stackoverflow.com/questions/3481828/how-to-split-a-string-in-java) – NielsNet Aug 23 '18 at 17:16
  • `response.split("Charge")[0].split("RESPONSE=")[1]` will give you what you're looking for. – Louis-wht Aug 23 '18 at 17:51

1 Answers1

0

You can do this with an indexof and a substring, as shown in this example :

String response = "You are about to purchase abcd package for 20 usd. Charge 1usd&encoding=0&SessionOp=end";
String newresponse = response;
int index = response.indexOf('&');
if (index != -1) {
    newresponse = newresponse.substring(0, index);
}
return newresponse;

Here, newreponse will contains the split String.

Emmanuel H
  • 82
  • 8