Click here to Skip to main content
13,590,909 members
Rate this:
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 9:31am
Updated 20-Nov-12 11:11am
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.
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.

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...
RickSharp 20-Nov-12 17:35pm
I appreciate your help.
Sergey Alexandrovich Kryukov 20-Nov-12 17:53pm
Great. If you still have concerns, please don't hesitate to ask.
Sergey Alexandrovich Kryukov 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 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 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 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 20-Nov-12 17:54pm
Absolutely. Good luck, call again.
RickSharp 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web02-2016 | 2.8.180618.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

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