Click here to Skip to main content
15,867,939 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
I need to read a CSV file, strip the delimiters and save a new file with the extension .TXT

Question improved.


Rick
Posted
Updated 20-Nov-12 11:11am
v2
Comments
Sergey Alexandrovich Kryukov 20-Nov-12 15:56pm    
SCV is a text file. Why won't you "insert code here" by yourself. If you have particular concerns, ask some questions. This is a Questions & Answers forum.
--SA
RickSharp 20-Nov-12 16:58pm    
Easy Sergey. I'm not looking for a handout. And a CSV file is not a TXT file. Thats why one is named COMMA delimited and the other one is named TAB delimited.

Sheesh.
R. Giskard Reventlov 20-Nov-12 17:04pm    
Actually, a csv file is a text file. You can open a CSV file with a text editor and read the content. What you want to do, effectively, is just change the delimiters that separate cell content and, probably, change the file extension.
RickSharp 20-Nov-12 17:08pm    
Yes, exactly. A CSV file is a text file, but yes I needed to strip the delimiters and change the extension to .TXT which would change it from being a .CSV file. I'll be more specific going forward.
Sergey Alexandrovich Kryukov 20-Nov-12 17:30pm    
OK, now you agree it's text -- much better. I'm already afraid to surprise you too much, but there is not such thing as "extension". It was on some very old OS, hardly applied animore. "TXT" in *.TXT means literally nothing; there is some data in Registry telling the Shell what application to use by default, nothing else. Even "EXE" and "DLL" means nothing at all. All the difference between file types or formats are in their contents, nowhere else. There were OS where it wasn't the case, maybe they still exist... Surprised?

Now, your problem is indeed just to replace delimiters. What's the difficulty? Read line by like, replace, output line by line -- as simple as that...
--SA

1 solution

One way is to read the file into a string and then parse the string to replace commas with a tab character except when the comma is inside a pair of single or double quotes.
You will also have to handle when a comma is used as a decimal separator. So, there's a hint: now write some code and, when you get stuck on a specific issue or get an exception, then you ask a question.
 
Share this answer
 

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