【记录】字符串固定位数中插入逗号

参数说明:
str:要插入逗号的字符串
index:插入的位数
如有需要也可将逗号转为其他字符串,也可作为参数传入

public String insertCommaInStr(String str,int index){
if (index<=0){
return null;
}
//去除字符串中的\n和\t符号,头尾去空
String string = str.replaceAll("\n|\t", "").trim();
StringBuilder sb = new StringBuilder();
sb.append(string);
for (int i = sb.length()-index; i >0; i-=index) {
sb.insert(i,",");
}
return sb.toString();
}
posted @   植树chen  阅读(94)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示