题目:实现一个函数把字符串中的每个空格替换成“20%”。
字符替换问题,replaceAll();方法的使用
输入:"hello world"
输出:hello20%20%world
java代码如下:
public class Test {
public static void main(String[] args) {
String string="hello world";
System.out.println(spaceReplace(string));
}
private static String spaceReplace(String string) {
// TODO Auto-generated method stub
return string.replaceAll(" ", "20%");
}
}