目录
replace:
简而言之就是用
新的字符/字符串 替换 旧的字符/字符串,
public String replace(char oldChar, char newChar)
String src = new String("ab686cd999");
System.out.println(src.replace("6","f"));->abf8fcd999
System.out.println(src.replace("68","f"));->abf8fcd999
System.out.println(src.replace('6','f'));->abf6cd999
replaceAll:
简而言之和replace一样,唯一不同的是,replaceAll可以正则表达式的替换,列如数字
String src = new String("ab686cd999");
System.out.println(src.replaceAll("\\d","f"));->abfffcdfff
replaceFirst:
就是只替换遇到的第一个,后面不管
String src = new String("ab686cd999");
System.out.println(src.replaceFirst("\\d","f"));->abf86cd999