1、每隔N位,插入一个","; 2、字符串对象:str引用; StringBuilder str = "1234567890asdfgnbvcxh"; if(str is not null && str.length()>=N){ 一、从左--->右插入: for (int i = N;i<str.length();i+=N+1){ //从--->每隔N位,插入一个"," str.insert(N,","); } 二、从左<---右插入: for (int i = str.length - N;i>=0;i-=N){ //从<---每隔N位,插入一个"," str.insert(N,","); } }
相关分类