public class Test01 {
public static void main(String[] args) {
String number = "123,456,5234,52345,63456,7456,7";
String newNumber = number.replace(",", ";");
System.out.println(newNumber);
}正則表達式
}spa
結果:blog
123;456;5234;52345;63456;7456;7字符串
public class Test01 {
public static void main(String[] args) {
//replaceAll,replace,replaceFirst的區別
String strTmp = new String("BBBBBBBYYYYYYY");
//replaceAll支持正則表達式和字符替換
strTmp = strTmp.replaceAll ("\\D", "Y");
System.out.println(strTmp);
strTmp = strTmp.replaceAll ("Y", "N");
System.out.println(strTmp);
//replace支持字符和字符串替換
strTmp = strTmp.replace("N", "C");
System.out.println(strTmp);
//只替換第一個字符
strTmp = strTmp.replaceFirst("\\D", "q");
System.out.println(strTmp);
}class
}im
結果:static