Displaying comma in .csv fille

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2008
Posts: 20
Reputation: saneeha is an unknown quantity at this point 
Solved Threads: 0
saneeha saneeha is offline Offline
Newbie Poster

Displaying comma in .csv fille

 
0
  #1
Oct 14th, 2008
I am saving the output of my program in .csv file.
I need to save a variable's value in one column, but the value may contain comma.
When the program encounters a comma it places half of the variable's value in
the next column.

Is there any way through which I can avoid the placement of value in the next column..
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Displaying comma in .csv fille

 
0
  #2
Oct 14th, 2008
Put the thing in quotes
1,"hello, world",2
would be 3 columns.

Use excel to save a simple csv format file with a field containing a comma.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 20
Reputation: saneeha is an unknown quantity at this point 
Solved Threads: 0
saneeha saneeha is offline Offline
Newbie Poster

Re: Displaying comma in .csv fille

 
0
  #3
Oct 14th, 2008
If double quotes are used it prints the variable name instead of value...
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Displaying comma in .csv fille

 
0
  #4
Oct 14th, 2008
Or you could just post some actual code....
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: Displaying comma in .csv fille

 
0
  #5
Oct 14th, 2008
Interesting that you want to use a format specifically meant for separating individual values with commas, but need to retain information with commas inside it.

A good way of doing this would be to make your own tokenizer and only parse information when a stack is empty.

When you encounter quotes, push it onto the stack and read characters contiguously, even if it is a comma.

When you encounter quotes again, pop the original quote off of the stack and let your custom tokenizer do its thing, like normal.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC