Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding split method

 
arav vara
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have a csv file in the below format. H,"TestItems_20100107.csv",07/01/2010,20:00:00,"TT1198","MOBb","AMD",NEW,,

I require the split command to ignore the commas inside the double quotes . So i used the below split command from an earlier post. Pasted the URL that i took this command String items[] = line.split(",(?=([^\"]\"[^\"]\")[^\"]$)"); System.out.println("items.length"+items.length);

http://stackoverflow.com/questions/1757065/java-splitting-a-comma-separated-string-but-ignoring-commas-in-quotes/1757107

When i run for this CSV data I am getting the items.length printed as 8. The last two commas at the end of line after "NEW" are ignored. I want the split command to pick up these commas and return me the length as 10. It's not picking up the null commas if it's in end but it's picking it up if it's in the middle of string. Not sure what i need to modify in the split command to resolve this issue. Also in the csv file Double quotes within the contents of a Text field can be repeated (e.g. "This account is a ""large"" one")
 
Henry Wong
author
Marshal
Pie
Posts: 21208
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Use the overloaded split() methods instead -- the one that takes a limit. And choose a negative value as the limit.

Henry
 
arav vara
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot. Will try it. Could you please post me some good websites for learning regex patterns.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49412
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try here for regular expressions.
 
arav vara
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot. How do i give points and accept the answer in this forum?
 
Henry Wong
author
Marshal
Pie
Posts: 21208
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
arav vara wrote:Thanks a lot. How do i give points and accept the answer in this forum?


This topic has already been marked as resolved. If it had not, then you can request that it be marked as such, by clicking the big resolve button near the other buttons. And a moderator will review and mark accordingly.

We do not use a point system on the ranch.

Henry
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"arav vara", I suggest you read your private messages and follow the instructions in them.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic