cndavy

导航

统计
 

private static String[] getSplit(String txt) throws Exception { ArrayList<String> list = new ArrayList<String>(); int b=0; int begin=0; StringBuffer buff=new StringBuffer(); int iLen= txt.length(); for (int i =0 ;i<iLen;i++){ String s=txt.substring(i,i+1); switch (b){ case 0: if (s.equals("\"")){ b=1; begin=i; continue; }else throw new Exception("没有引号"); case 1: // 进入 引号中 if (s.equals("\"")) { b=2; continue; }else { buff.append(s); continue; } case 2: if (s.equals("\"")) { //字段中出现 引号 "asdfasd "" qweqwe" buff.append("\""); b=1; } else if (s.equals(",")){ b=0; list.add(buff.toString()); buff=new StringBuffer(); } } } int resultSize = list.size(); String[] result = new String[resultSize]; return list.subList(0, resultSize).toArray(result); }

  

posted on 2018-01-23 11:09 cndavy 阅读(...) 评论(...) 编辑 收藏