关于java:用%20替换空白

Replace white space with %20

本问题已经有最佳答案,请猛点这里访问。

我必须用%20替换字符串中的所有空格。

我尝试在此模式title.replaceAll("","%20");中使用方法replaceAll(显然title是一个字符串),但这不起作用,结果是带有所有空白的初始字符串


不要使用全部替换,我发现它永远无法按预期工作。 只需String.replace即可完成工作。

1
2
3
4
5
6
7
8
public static void main (String [] args) {

    String test ="H E L L O";

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

}

结果

1
H%20E%20L%20L%20O