String str = "20090901|+|029275|+|0|+|620|+||+||+||+|6226661400538058|+||+|20090831";要求按"|+|"分隔;str.split(regex);regex应该是什么呢?试了很多遍,都没有成功,请高手赐教!

解决方案 »

  1.   

    | +都是正则的特殊字符 需要 转义    /**
         * @param args
         */
        public static void main(String[] args)
        {
            String str = "20090901|+|029275|+|0|+|620|+||+||+||+|6226661400538058|+||+|20090831";        String[] temp = str.split("\\|\\+\\|");
            for (int i = 0; i < temp.length; i++)
            {
                
                System.out.println(temp[i]);
            }    }
      

  2.   


            String str = "20090901|+|029275|+|0|+|620|+||+||+||+|6226661400538058|+||+|20090831";        String[] temp = str.split("\\|\\+\\|");
            for (int i = 0; i < temp.length; i++)
            {
                if ("".equals(temp[i]))
                {
                    return;
                }
                System.out.println(temp[i]);
            }    }
      

  3.   

    是 continue去掉空字符,呵呵 return是对的,对不起。。    /**
         * @param args
         */
        public static void main(String[] args)
        {
            String str = "20090901|+|029275|+|0|+|620|+||+||+||+|6226661400538058|+||+|20090831";        String[] temp = str.split("\\|\\+\\|");    
            for (int i = 0; i < temp.length; i++)
            {
                if ("".equals(temp[i]))
                {
                    continue;
                }
                System.out.println(temp[i]);
            }    }