zoukankan      html  css  js  c++  java
  • CSV 文件处理成 String[] ,网银下载的文本中使用逗号分割, 使用双引号标记字段. 使用String split 会出现把引号中的逗号识别的情况 例如 " ,,,, " , "aaa"


    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); }

      

  • 相关阅读:
    LRu Cache算法原理
    c# 哈希表
    c# 获取二维数组的行数和列数
    Linq
    DataTable使用
    Wpf学习
    数据库配置
    js 数字保留两位小树
    平面数据转换为树形结构
    mysql操作
  • 原文地址:https://www.cnblogs.com/cndavy/p/8334679.html
Copyright © 2011-2022 走看看