|
-
February 10th, 2012, 09:52 AM
#1
Convert csv to pipe delimited text
Hi
I have been looking around and can only see how to convert text to CSV.
Basically i have a single line, quote qualified csv file that i want to turn into a standard pipe delimited text file
so
"545454","yes","yes","no","boo, hoo"
to
545454|yes|yes|no|boo, hoo
Any ideas?
Thank you
.NET 4.0 with VS2010 Pro
-
February 10th, 2012, 11:40 AM
#2
Re: Convert csv to pipe delimited text
If there aren't any spaces between the quotes and the comma (i.e ","), you could load up the file in a StringBuilder and then call:
Code:
sb.Replace("\".\"", "|"); // replace "." with |
sb.Replace("\"", ""); // remove the leading and trailing "
-
February 10th, 2012, 03:06 PM
#3
Re: Convert csv to pipe delimited text
Of course you can run into issues if your data may contain quotes as part of the data.
Always use [code][/code] tags when posting code.
-
March 4th, 2012, 05:41 PM
#4
Re: Convert csv to pipe delimited text
Converting a CSV file into a pipe delineated file should be simple and easy. The way I would approach is to write a lexer and parser for the csv file, process it into records, and then output those records into the format of your choice. For the lexer, you can have a class which iterates through all the characters in the file and keeps output tokens for the commas, the quotes, the text, and anything else that might pertain to csv format. I would also write a parser into which would be inputted the tokens, and this would verify the syntax and generate the records for the csv file. Outputting into a new format is a simple as writing the file. I might not be the wisest guy but I think that a simple search on lexing and recursive descent parsing will provide enough knowledge to achieve your goal.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|