此类 是在jdk1.4下编译的 ,注意replace 和replaceAll 在jdk1.4 和jdk5.0 的差别!
package com.dvnchina.boss.util.commons;
public class StringForPrint {
/**
*
* @param str 需要处理的字符串
* @param sep 分隔符:如"," "|"
* @param sepForPrint 打印时的分隔符 "||","&&" 等
* @param perLine 每行需几个
* @return 处理好但换行符的字符串
* @param total 每行字符数量标准
*/
public static String returnMoreLineString(String str,String sep,String sepForPrint,int perLine,int total){
String result = "";
int len = 0 ;
String arr[] = str.split(sep);
if(arr.length > 0){
for(int i=1;i<=arr.length;i++){
len = 0;
for(int j=0;j<perLine && j< arr.length;j++){
len += arr[j].length();
}
if(len <= total){
if(i%perLine == 0){
arr[i-1] = arr[i-1].concat(sepForPrint);
}
result = result+(arr[i-1]+",") ;
}else{
if(i%(perLine-1) == 0){
arr[i-1] = arr[i-1].concat(sepForPrint);
}
result = result+(arr[i-1]+",") ;
}
}
}
result = result.substring(0, result.length() - 1).replaceAll(sepForPrint+sep, sepForPrint) ;
System.out.println(result);
return result;
}
}