Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I need to read a CSV file, strip the delimiters and save a new file with the extension .TXT
 
Question improved.
 

Rick
Posted 20-Nov-12 9:31am
Edited 20-Nov-12 11:11am
v2
Comments
Sergey Alexandrovich Kryukov at 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 at 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.
mark merrens at 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 at 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 at 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
RickSharp at 20-Nov-12 17:35pm
   
I appreciate your help.
Sergey Alexandrovich Kryukov at 20-Nov-12 17:53pm
   
Great. If you still have concerns, please don't hesitate to ask.
--SA
Sergey Alexandrovich Kryukov at 20-Nov-12 17:24pm
   
Not text file? OK, that ends the story. You cannot solve the problem is this is what you think. Maybe, think again. The problem is trivial though, nothing really to talk about...
--SA
RickSharp at 20-Nov-12 17:31pm
   
Not sure why you're being hostile Sergey. This is my first post and I'm totally a beginner. If this is how new user's are treated here I can certainly post somewhere else and delete my account and not recommend codeproject to my friends. First post buddy, show a little restraint from belittling new users maybe?
Sergey Alexandrovich Kryukov at 20-Nov-12 17:48pm
   
Where do you see hostility? You make a mistake, I'm trying to fix it for you, that's all. You should not just take it personally.
There is no shame in your mistakes at all. And please understand that there is no any disrespect at all; just the opposite -- being a novice means pretty hard time and trying hard to sort things out should be encouraged. I am sorry if you perceive my somewhat ironic style of talking as some hardness, but believe me, there is nothing negative in it to you personally. OK?
 
Now, you see, I somehow provided you some clarification about "extensions". You are going to have some kind of trouble if you try to treat something which is just a part of name in any special way. I also gave you some hint on what to do. Isn't that enough to write your code? Everything you need is in System.String type and two IO types: System.IO.StreamReader and System.IO.StreamWriter (ReadLine, WriteLine, practically). If you look at MSDN help page one these 3 types, you will find all you need.
 
Will it resolve your problem?
 
By the way, take a look at CodeProject answers: so many people got help, in many more rare cases, in extremely tricky situations. I personally try to avoid giving cookbook recipe, as they mostly a waste of time. A developer should understand every like written in all detail. I hope you can understand it...
 
--SA
RickSharp at 20-Nov-12 17:52pm
   
Thank you Sergey, being that I'm completely new, I have a large learning curve ahead. Yes, that makes sense. Sometimes its simply thinking through what you need done step by step and start coding. You helped me understand that extensions are simply telling the shell what application to use. Thank you for that.
Sergey Alexandrovich Kryukov at 20-Nov-12 17:54pm
   
Absolutely. Good luck, call again.
--SA
RickSharp at 20-Nov-12 16:54pm
   
Thank you Mark. Thats a good place to start. Let me write some code and I'll get back to you on any specific issues.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 490
1 Gihan Liyanage 338
2 ChauhanAjay 180
3 Vinay Mistry 160
4 Sergey Alexandrovich Kryukov 153
0 Sergey Alexandrovich Kryukov 9,011
1 OriginalGriff 7,941
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100