日期:2014-05-20 浏览次数:20696 次
public static void main(String[] args) { String str = "DYNFLIGHT#A###2012/07/02 14:42:54#START#186###"; Pattern pattern = Pattern.compile("#"); Matcher matcher = pattern.matcher(str); List<String> list = new ArrayList<String>(); int startIndex = 0; while(matcher.find()){ int endIndex = matcher.start(); //这里可以判断str.substring(startIndex, endIndex).length() == 0替换成null list.add(str.substring(startIndex, endIndex)); startIndex = endIndex + 1; } for(String s : list){ System.out.print(s +","); } }