replace(char oldChar, char newChar)
返回一个新的字符串,它是通过用 newChar 替换此字符串中出现的所有 oldChar 而生成的。
public class TestReplace {
public static void main(String[] args) {
String s = "This is my original string ,it is very good!"
String r = "at"
s = s.replace("is",r)
System.out.println(s)
}
}
输出结果:
That is my original string ,it is very good!
replace() 方法通过用 newChar 字符替换字符串中出现的所有 oldChar 字符,并返回替换后的新字符串。
语法:public String replace(char oldChar, char newChar)
参数解释:oldChar -- 原字符;newChar -- 新字符。