字符串分组,字符串中每两位字符加一个空格
时间:2021-09-02 17:08:18
收藏:0
阅读:24
String str = "123456";
// 可以使用任意字符串分隔,如$1-
String result1 = str.replaceAll("(.{2})(?=.{2})", "$1 ");
String result2 = str.replaceAll("(.{2})(?=.{2})", "$1-");
结果如下

原文:https://www.cnblogs.com/penghanghang/p/15217388.html
评论(0)