就是一个编号有16位的数字,我想把每个编号分为一行怎么写呢?
比如:
str = "2000123542120000是在工2000123542124789后面是非功过,(中国)2000134879200001后面也有文字"
这么一段,分为三行
str1 = 2000123542120000是在工
str2 = 2000123542124789后面是非功过,(中国)
str3 = 2000134879200001后面也有文字谢谢!!!!!

解决方案 »

  1.   

    文字中不包含数字
    import java.util.regex.*;
    public class T1116 {    /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            String str = "2000123542120000是在工2000123542124789后面是非功过,(中国)2000134879200001后面也有文字";
            Pattern p = Pattern.compile("(\\d{16})([^\\d]+)");
            Matcher m = p.matcher(str);
            while(m.find()){
                System.out.println(m.group(1)+m.group(2));
            }    }}//如果包含数字会出问题,看其他高手怎么解决
      

  2.   

    Vector<String> result = new Vector<String>();
    for (int i = 0; i < str.length(); i++) {
        if (str.charAt(i) >= '0' && str.charAt(i) <='9') {
             for (int j = i; j < 15; j++) {
                 if (str.charAt(i) < '0 ' || str.charAt(i) > '9') {
                     System.out.println("格式不正确");
                     right = false;
                 }
                 else {
                     right = true;
                 }
             }
        }
        if (right) {
            int nextNum = 0;
            for (int x = i + 15; x < str.length(); x++) {
                if (str.charAt(x) <= '9' && str.charAt(x) >= '0') {
                    nextNum = x;
                    break;
                }
            }
            if (nextNum != 0) {
                result.add(str.substring(i,nextNum));
            } 
            
        }
        i = nextNum;
    }
      

  3.   

    Vector<String> result = new Vector<String>();
    boolean right = false;
    for (int i = 0; i < str.length(); i++) {
        right = false;
        if (str.charAt(i) >= '0' && str.charAt(i) <='9') {
            for (int j = i; j < 15; j++) {
                if (str.charAt(j) < '0 ' || str.charAt(j) > '9')
                    right = false;
            
                else 
                    right = true;
            
            }
        }
        if (right) {
            int nextNum = 0;
            for (int x = i + 15; x < str.length(); x++) {
                if (str.charAt(x) <= '9' && str.charAt(x) >= '0') {
                    nextNum = x;
                    break;
                }
            }
            if (nextNum != 0) {
                result.add(str.substring(i,nextNum));
            }     }
         i = nextNum;
    }
      

  4.   

    }
    i = nextNum - 1;
    }
      

  5.   

    import java.util.regex.*;
    public class Test{
    public static void main(String[] args){
    String s = "2000123542120000是在123工2000123542124789后面是非功过,(中国)2000134879200001后面也有文字";
    Pattern pa = Pattern.compile("\\d{16}[\u4e00-\u9fa5]+\\d{0,15}[\u4e00-\u9fa5]+");
    Matcher ma = pa.matcher(s);
    while(ma.find()){
    System.out.println(ma.group(0));
    }
    }
    }
      

  6.   

    哈哈,不好意思,上面的那个错了,我修改了一下,这下可以了:import java.util.regex.*;
    public class Test{
    public static void main(String[] args){
    String s = "2000123542120000是在123工2000123542124789后面是非功过,(中国)2000134879200001后面也有文字";
    Pattern pa = Pattern.compile("\\d{16}[^\\d]+(\\d{0,15}?)[^\\d]+");
    Matcher ma = pa.matcher(s);
    while(ma.find()){
    System.out.println(ma.group());
    }
    }
    }