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
replaceAll,replace,replaceFirst的区别
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);
}
}
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有