今天提了这样一个需求,要把 “0103020511"这样一串字符,两个为一组,中间用英文逗号隔开,也就是入参是"0103020511”,出参格式为"01,03,02,05,11"
直接上代码:
String typeCode = ''0103020511";
typeCode = typeCode.replaceAll("(.{2})", “$1,”);
if (typeCode.endsWith(",")) {
typeCode = typeCode.substring(0, typeCode.length() - 1);
}
转化后的typecode就是"01,03,02,05,11"的效果啦~
一串数字字符两个一组用英文逗号隔开
最新推荐文章于 2022-11-03 18:43:33 发布