Regex for java.util.Scanner for csv files? -


i want read csv file using java.util.scanner. first attempt looked promising:

 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 elements      linescanner.next();  }  

the challenge i'm facing line linescanner.usedelimiter(",");. csv has commas inside text , escaped double quotes:

 year,value,customer,nickname,rank  2012,45.56,t3456c,"mike, \"the gangster\"",1  2012,1237.35,"a453f", joe armagendon,2  2012,,x344,"frank weasel",3 

is there regex filters separators?

as mentioned nhahtdh, should use parser, way csv works bit more complicated example.

there many libraries out there. 1 i've used , forked csvfile. it's pretty easy use , job right.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -