使用“;”替换过字符串中的“,”

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);
}

}

结果:

123;456;5234;52345;63456;7456;7

 

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);

public class Main {

    public static void main(String[] args) {
	    String strTmp = new String("BBBBYYYYYY");

	    strTmp = strTmp.replaceAll("\\D","Y");
	    System.out.println(strTmp);
        strTmp = strTmp.replaceAll("Y","N");
        System.out.println(strTmp);

        strTmp = strTmp.replace("N","C");
        System.out.println(strTmp);

        strTmp = strTmp.replaceFirst("\\D","q");
        System.out.println(strTmp);
    }
}

 结果:

YYYYYYYYYY
NNNNNNNNNN
CCCCCCCCCC
qCCCCCCCCC

 

 

 

 

相关文章:

  • 2022-12-23
  • 2021-05-08
  • 2022-12-23
  • 2022-02-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2022-02-09
  • 2021-08-20
相关资源
相似解决方案