Click here to Skip to main content
Rate this: bad
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.

Posted 20-Nov-12 10:31am
Edited 20-Nov-12 12:11pm
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.
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.
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...
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.
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...
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...
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.
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
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.

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

  Print Answers RSS
0 Mathew Soji 334
1 Maciej Los 295
2 BillWoodruff 290
3 Afzaal Ahmad Zeeshan 257
4 DamithSL 225
0 OriginalGriff 6,369
1 Sergey Alexandrovich Kryukov 5,973
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,045

Advertise | Privacy | Mobile
Web04 | 2.8.1411019.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