/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String ukey1="SZBSK00000000022";
String ukey2="SZBSK00000000222";
List a=getContinueString(ukey1,ukey2);
for (Object object : a) {
System.err.println(object);
}
}
/**
* 获取2个字符串的连续值 并返回list集合
*/
public static List getContinueString (String s1, String s2) {
//获取公共字符串部分
String ccommonStr=getSubString(s1,s2);
int ukeyStr1 = Integer.parseInt(s1.replace(ccommonStr, ""));
int ukeyStr2 = Integer.parseInt(s2.replace(ccommonStr, ""));
//获取剩余字符串的位数
int len = String.valueOf(ukeyStr2).length();
List list = new ArrayList();
for (int i = ukeyStr1; i < ukeyStr2+1; i++) {
StringBuffer sb=new StringBuffer();
sb.append(ccommonStr);
sb.append(frontCompWithZore(i,len));
list.add(sb.toString());
}
return list;
}
/**
* 取得字符串公共部分
*/
public static String getSubString(String s1, String s2) {
if (s1.length() > s2.length()) {
String temp = s1;
s1 = s2;
s2 = temp;
}
int n = s1.length();
int index = 0;
ok: for (; n > 0; n--) {
for (int i = 0; i < s1.length() - n + 1; i++) {
String s = s1.substring(i, i + n);
if (s2.indexOf(s) != -1) {
index = i;
break ok;
}
}
}
return s1.substring(index, index + n);
}
/**
* 将元数据前补零,补后的总长度为指定的长度,以字符串的形式返回
*/
public static String frontCompWithZore(int sourceDate,int formatLength)
{
/*
* 0 指前面补充零
* formatLength 字符总长度为 formatLength
* d 代表为正数。
*/
String newString = String.format("%0"+formatLength+"d", sourceDate);
return newString;
}