java实现CSV 字段分割
程序员文章站
2024-03-05 21:34:37
支持引号嵌套,逗号分割
private static string[] cvsfield(string line){
list
支持引号嵌套,逗号分割
private static string[] cvsfield(string line){ list<string> fields = new linkedlist<>(); char[] alpah = line.tochararray(); boolean isfieldstart = true; int pos = 0; int len = 0; boolean yinhao = false; for(char c : alpah){ if(isfieldstart){ len = 0; isfieldstart = false; } if(c == '\"'){ yinhao = !yinhao; } if(c == ',' && !yinhao){ fields.add(new string(alpah, pos - len, len)); isfieldstart = true; } pos++; len++; } return fields.toarray(new string[0]); }
以上所述就是本文的全部内容了,希望大家能够喜欢。