2

I have to replace all withe space in a string with %20.

I try to use the method replaceAll in this mode title.replaceAll(" ", "%20");(obviously title is a String) but this doesn't work and the results is the initial string with all white space

Torre106
  • 39
  • 2
  • 6

1 Answers1

4

Solution

Don't use replace all I find it doesn't ever work as expected. Just String.replace and that should get the job done just fine.

public static void main (String [] args) {

    String test = "H E L L O";

    test = test.replace(" ", "%20");
    System.out.println (test);

}

Result

H%20E%20L%20L%20O
cunniemm
  • 679
  • 5
  • 19