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.
You should do it like: flag1 = flag1. replaceAll(" ", "%20");
replaceAll(" ", "%20"); System. out. println(URL);
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..
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")
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With