Java双重循环实现任意字符串中提取数字子串


public class Test2{
 public static void main(String[] args) {
  String s = "211ahn678rh2kkk07312n3e12w4";
  int begin = 0;
  outer:for(;begin<s.length();){
   if(!(s.charAt(begin)>=48 && s.charAt(begin)<=57)){
    begin++;
    continue;
   }
   int end = begin;
   for(;end<s.length();){
    if(!(s.charAt(end)>=48 && s.charAt(end)<=57)){
     System.out.println(s.substring(begin,end));
     begin = end;
     break;
    }else{
     end++;
     if(end == s.length()){
      System.out.println(s.substring(begin));
      break outer;
     }else{
      continue;
     }
    }
   }
  }
 }
}

你可能感兴趣的:(Java双重循环实现任意字符串中提取数字子串)