求最大连续递增数字串(如“ads3sl456789DF3456ld345AA”中的“456789”)
public static String FindMaxSequence(String s){
char[] chars = s.toCharArray();
int max = 0;
int end = -1;
int pre = 0;
for(int i = 0; i< chars.length; i++){
if(chars[i] >= '0' && chars[i] <= '9'){
pre++;
if(pre > max)
{
max = pre;
end = i;
}
}
else
pre = 0;
}
if(max > 0)
{
return s.substring(end - max + 1, end);
}
else
return null;
}