我想使用java.util.Scanner
. 第一次尝试看起来很有希望:
Scanner scanner = new Scanner(cFile);
while (scanner.hasNextLine()) {
String curLine = scanner.nextLine().trim();
this.processRow(curLine);
}
private void processRow(String workString) {
Scanner lineScanner = new Scanner(workString);
lineScanner.useDelimiter(",");
// .next goes through the elements
lineScanner.next();
}
我面临的挑战是生产线lineScanner.useDelimiter(",");
。我的 CSV 在文本中有逗号并转义了双引号:
Year,Value,Customer,NickName,Rank
2012,45.56,T3456C,"Mike, \"The Gangster\"",1
2012,1237.35,"A453F", Joe Armagendon,2
2012,,X344,"Frank the weasel",3
是否有只过滤分隔符的正则表达式?