Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to replace space with %20 in url in android in jsonparsing [closed]

Tags:

java

In my application i want to replace space with %20 in my string.I tried in this way,

String flag1="http://74.208.194.142/admin/upload_image/1342594079_images (2).jpg";
flag1.replaceAll("", "%20");

But it is not working please help me.I am getting null pointer exception.

like image 490
user1083266 Avatar asked Oct 01 '12 10:10

user1083266


People also ask

How to remove 20 from url in android?

You should do it like: flag1 = flag1. replaceAll(" ", "%20");

How to replace space with 20 in url Java?

replaceAll(" ", "%20"); System. out. println(URL);


3 Answers

You should do it like:

flag1 = flag1.replaceAll(" ", "%20");

first you were putting empty string instead of space.. and second you must return the value into the flag1 variable..

like image 129
Nermeen Avatar answered Nov 15 '22 14:11

Nermeen


Have a look at http://docs.oracle.com/javase/1.5.0/docs/api/java/net/URLEncoder.html

It is not only the blanks that need to be replaced. URLs consist of special caracters for special meanings (e.g. the question mark to start the query string)

String flag1 = URLEncoder.encode("This string has spaces", "UTF-8")
like image 30
thobens Avatar answered Nov 15 '22 15:11

thobens


In flag1.replaceAll(), your space is missing. try:

String flag1="http://74.208.194.142/admin/upload_image/1342594079_images (2).jpg";
flag1 = flag1.replaceAll(" ", "%20");

and set the result to the flag1.

like image 38
stealthjong Avatar answered Nov 15 '22 14:11

stealthjong