Question: We recently received a bunch of files with tab-delimiters.

We were having difficulties importing them in sql server database.

The vendor who sent the files also sent the code below for us to use in converting the files from tab to comma delimiters.

How do I use this file in visual studio.

I have used visual studio several times befor but I have not used it with just single file such as this.

```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace TabToComma
{
   class Program
   {
      static void Main(string[] args)
      {
         StreamReader sr;
         StreamWriter sw;

         sr = new StreamReader(@"c:\input.txt");
         sw = new StreamWriter(@"c:\output.txt");

         string nextline;
         string replacedline;

         while (sr.Peek() >= 0)
         {
            nextline = sr.ReadLine();
            replacedline = nextline.Replace('\t',','); // replace each tab in line with a comma
            sw.WriteLine(replacedline);
         }
         sr.Close();

         sw.Close();

      }
   }

}

```

Alternatively, if someone knows how I can accomplish same thing using vbscript please point me in the right direction.

Thanks alot in advance

Answer: 
Also, here's a replacement for the content of `Main()` that might make your life easier, as long as the files are of decent size:

```
foreach(string f in args) {
    System.IO.File.WriteAllText(f, System.IO.File.ReadAllText(f).Replace('\t', ','));
}

```

Compile and drag and drop all your files onto the resulting executable. They'll be converted automatically.

You can even grab the compiled executable from here: <http://dl.dropbox.com/u/2463964/TabsToCommas.exe> if you're having trouble compiling it.
OK, that was nice playing in the answers with all kind of methods how to replace characters in a string. But unfortunately, reality is not as easy as that. How do you handle data with comma's in it for example? Like `Telephone bill{tab}USD{tab}1,234.00` becoming `Telephone bill,USD,1,234.00`. An extra column is inserted and data gets corrupted because the database registers that your telephone bill was only one dollar. Luckily, the problem is not the other way around because even [The Scripting Guy](http://blogs.technet.com/b/heyscriptingguy/archive/2005/04/06/how-can-i-convert-a-comma-separated-values-file-to-a-tab-separated-values-file.aspx) doesn't have a waterproof solution for that.

What your vendor *should* have delivered is a line by line reader, where every line is split on the tab character into an array with all values. Then read out all values in the array to see if there is one or more comma's in the value and wrap it with double quotes. After that, the array is assembled to a string with a `join` on the comma to make it a 'real' [CSV file](https://www.rfc-editor.org/rfc/rfc4180).

But why go through all the hassle if you can tackle the problem at the source; why not flag your data as tab delimited in SQL?

```
BULK
INSERT TableYouWantToImportTo
FROM 'c:\input.txt'
WITH
(
FIELDTERMINATOR = '\t',
ROWTERMINATOR = '\n'
)
GO 

```