How to convert CSV to SCSV, TSV and PSV file using C#

Convert CSV file to SCSV, TSV and PSV file using CSharp

This blog post is a tutorial for converting comma separated values (CSV) file to other delimiter separated values file.

How To Code For : Convert CSV file to SCSV, TSV and PSV file using CSharp

Prerequisites:

Basic of C#, Windows Form

You’ll get Answers for:

1. How to convert CSV to into another DSV format.
2. How to create conversion tool for CSV to another DSV formats.
3. How to convert Comma Separated Values file to Semicolon, Colon, Tab, and Pipe separated values file

Tools used:

1. The code is created using Visual Studio 2013 Community Edition
2. Windows forms
3. Simple Label, Button, Radio, TextBox controls

DSV?

DSV stand for a Delimiter Separated Values. Delimiter can be comma(,),  semi-colon(;),  pipe(|),  hash(#) etc.

What are Input and Output?

Input: CSV file with at least few records in it.
Output: SCSV, TSV, PSV or CSV version of input file.

 

And… the Solution 🙂

The Code:

1. Required Variables

2. Select Input CSV

Function: SelectFile()
Return Type: string
Return Value: null or file name
Parameters: None
Usage: Allow to select a file from hard disk.

3. Select Path

Function: SelectPath()
Return Type: string
Return Value: null or folder name
Parameters: None
Usage: Allow to select folder location on hard disk.

4. Update Output File Type

Function: updateOutput()
Return Type: void
Return Value: none
Parameters: extension type or delimited file type
Usage: Allow to convert CSV file into Delimited file format with given extension.

5. Select Delimited Output Options

Output Option(s)   File Extension
semi-colon *.scsv
colon *.csv
tab *.tsv
pipe *.psv
other *.txt

6. Convert it

Now Convert CSV file to SCSV, TSV and PSV file using CSharp.

The File.WriteAllLines() function create a new delimited file with a selected delimiter, and store it into the output path as provided.

The Screenshot:

Screenshot: Convert CSV to SCSV, TSV, PSV file using C#

Download Code From Github

One Response
  1. Jack

Leave a Reply

Your email address will not be published. Required fields are marked *