写一个函数,接受类似如下的输入
字符串:123a45b6789z233e
输出:
123
45
6789
233Java实现。

解决方案 »

  1.   

    应该是简单的方法了:import java.util.regex.*;public class hello {
    public static void main(String[] args) {
         String str="123a45b6789z233e";
         String regEx="(\\d+)"; 
         Pattern p=Pattern.compile(regEx); 
         Matcher m=p.matcher(str); 
         while (m.find())
         {
           System.out.println(m.group(0)); 
         } 
             } }
      

  2.   


    printNumStr(String str) {
        String tmp="";
        for (int i=0; i<str.length(); i++) {
            if (str.charAt(i)<'0' || str.charAt(i)>'9') {
                if (tmp.length()>0) {
                    System.println(tmp);
                    tmp = "";
                }
            } else {
                 tmp += str.substring(i,1);
            }
        }
    }
      

  3.   

    要是我就这样做:
    System.out.println("123a45b6789z233e".replaceAll("\\D+","\n"));
      

  4.   

    public class Test {    public static void main(String[] args) {
            String s = "123a45b6789z233e";
            String[] ss = s.split("[^\\d]+");
            for (int i = 0; i < ss.length; i++) {
                System.out.println(ss[i]);
            }
        }
    }
      

  5.   

    to:helpall(was jl) ( ) 信誉:102 
    小弟想问下你  "123a45b6789z233e".replaceAll("\\D+","\n");这个表达式中replaceAll方法中第一个参数你用"\\D+"表示什么意思呀,我想了很久没想明白,还望告知!