This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to skip commas, in CSV file generator? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to skip commas, in CSV file generator?" Watch "How to skip commas, in CSV file generator?" New topic
Author

How to skip commas, in CSV file generator?

Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 261
I have a problem while creating the CSV file. I use to write the CSV file by separating with delimiter "|", this works fine if any text doesn't have any commas (","). The problem is if any text contains comma, then the remaining text continues to next cell, which is wrong. look into the examples

Perfect line:

10|001300221|SIMSON||WILLIAMS|A|20080818|1525|8753||HOLZGRAFE|| PEDIATRICS INTENSIVE CARE|ASSISTANT PROFESSOR/CLINICIAN|GUH PASQUERILLA HEALTHCARE CNT

In the above case, CSV writes in the same cell and then fine.

with comma:


10|001300221|SIMSON||WILLIAMS|A|20080818|1525|8753||HOLZGRAFE|| PEDIATRICS, INTENSIVE CARE|ASSISTANT PROFESSOR/CLINICIAN|GUH PASQUERILLA HEALTHCARE CNT


look at the bold sentence, there you see the comma and the line after comma is seprating to next cell.
I don't want like that, is there anyway to skip that comma and need as it is in the written file?



Thanks,
Kumar
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Kumar Kuchipudi wrote:I have a problem while creating the CSV file. I use to write the CSV file by separating with delimiter "|", this works fine if any text doesn't have any commas (","). The problem is if any text contains comma, then the remaining text continues to next cell, which is wrong. look into the examples

Perfect line:

10|001300221|SIMSON||WILLIAMS|A|20080818|1525|8753||HOLZGRAFE|| PEDIATRICS INTENSIVE CARE|ASSISTANT PROFESSOR/CLINICIAN|GUH PASQUERILLA HEALTHCARE CNT

In the above case, CSV writes in the same cell and then fine.

with comma:


10|001300221|SIMSON||WILLIAMS|A|20080818|1525|8753||HOLZGRAFE|| PEDIATRICS, INTENSIVE CARE|ASSISTANT PROFESSOR/CLINICIAN|GUH PASQUERILLA HEALTHCARE CNT


look at the bold sentence, there you see the comma and the line after comma is seprating to next cell.
I don't want like that, is there anyway to skip that comma and need as it is in the written file?




it doesn't look to me like the line after the comma is separating to the next cell.

But anyways, I think I know what you mean to show. you say you are using the | as a delimiter, but somehow the comma is being used also as a delimiter? How is that happening?

edit: ok maybe you are using a class or utility that automatically parses with comma separators? If so I would ask why, if you don't want to parse according to commas?
Nikki Agr
Greenhorn

Joined: Nov 09, 2008
Posts: 13
How about you embed that string which contains a comma within double quotes?
Mathew Lee
Ranch Hand

Joined: Jun 08, 2009
Posts: 238
I recommend to use something unique say like $@$ etc which clearly distinguishes
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to skip commas, in CSV file generator?
 
Similar Threads
Reading A CSV File
exporting to CSV
Microsoft Office SDK for java
is it possible to export info to exel
Exporting html data to excel