Jamel Naghmouchi
Jamel Naghmouchi

Reputation: 313

Android url Concatenation

I'm asking about the right way to concatenate a url with values ! here my example "http://10.0.2.2/myFolder/page.php?value1=!!&value2=!!,+value1,+value2" I hope you will understand what I'm saying cause I'm new to Android and thank you.

Upvotes: 1

Views: 5467

Answers (3)

Arpit Patel
Arpit Patel

Reputation: 1571

you can use stringbuilder and append the as many lines and values you want to add

like wise in your case

StringBuilder sb = ("http://").append(address).append("/myfolder/page.php?").append(value1).append("=").append(value2);

and then use the following

sb.toString();

hope this might helps you.I have used this in my one of the projects

Upvotes: 1

Ian Newson
Ian Newson

Reputation: 7939

The other answer is almost correct, but you should be URL encoding the keys and values:

String uri = "http://" + address + "/myFolder/page.php?" + URLEncoder.encode(value1) + "=" + URLEncoder.encode(value2);

Upvotes: 1

Li3ro
Li3ro

Reputation: 1877

Jamal, Are you trying to concatenate the String: "http://10.0.2.2/myFolder/page.php?value1=!!&value2=!!,+value1,+value2" ?

If so, Please try the follwing:

String uri = "http://" + address + "/myFolder/page.php?" + value1 + "=" + value2;

Hope this helps

Upvotes: 0

Related Questions