Click here to Skip to main content
15,889,644 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

I have a couple of questions relating to my subject line.

How would I convert data in a text file, or even directly from say, a list buffer, to csv format? What class/functions/properties would come in handy? Can anyone maybe give me a function example?

Thanks,
Posted
Updated 15-Nov-10 22:50pm
v2

Hi there RudolfErasmum,

The String class will have handy functions like 'String.Split', as to create a CSV you will need to delimit your original text by a predetermined
character.

After you have split down your text the StringBuilder class will be a handy to rebuild your strings inserting a comma where required. A method that I would suggest using is Append.

It might help then to take a look at the StreamWriter class, to save your memory stream to a CSV file.

MSDN has a lot of information relating to these classes and the related methods.

Hope that helps.

Larrythemule
 
Share this answer
 
v2
 
Share this answer
 
Comments
Dalek Dave 16-Nov-10 5:09am    
Good Links
R. Erasmus 16-Nov-10 5:12am    
I've had a look at the links you send me and it is of great help, thx.
Read and writing file look at
System.IO area StringReader/StringWriter


manipulating strings:

StringBulder to build up lines

to read in

string[] fields = string.Split(',');
 
Share this answer
 
v2
Comments
R. Erasmus 16-Nov-10 5:13am    
I was looking for something more specific and less work, thx :)
CSV files are just text files whose content is made up of lines of text. Within each line of text fields are separated by commas. Thus all you need to do is to create a file with the .csv extension, and write your data to it. See here[^] for a sample that you could modify to your requirements.
 
Share this answer
 
Comments
Dalek Dave 16-Nov-10 5:14am    
Good point.
R. Erasmus 16-Nov-10 5:21am    
Your answer was noted.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900