-1

I have the following which works fine:

    StreamWriter outputFile = new StreamWriter(@"C:\out.txt");

    string header =  "ProgramDate" +  "," +
                     "ProgTime";

    outputFile.WriteLine(header);

    outputFile.Close();

instead of the comma delimited, how do I make it tab delimited. Or how do I make it tab delimited to begin with? I searched online but could not find an answer to this.

dash
  • 89,546
  • 4
  • 51
  • 71
Nate Pet
  • 44,246
  • 124
  • 269
  • 414
  • 9
    Replace the "," with "\t" as this is the character code for tab. Plenty of examples on SO - see http://stackoverflow.com/questions/366124/inserting-a-tab-character-into-text-using-c-sharp – dash Dec 06 '11 at 21:28

2 Answers2

5

Just substitute the delimiter character you want.

StreamWriter outputFile = new StreamWriter(@"C:\out.txt");

string header =  "ProgramDate" +  "\t" +
                 "ProgTime";

outputFile.WriteLine(header);

outputFile.Close();
jac
  • 9,666
  • 2
  • 34
  • 63
0

Also, not sure if this would be an option you would consider looking into but, no need to reinvent the wheel, here's an open source CSV library.

If you just writing this for learning purposes or want to skip and licencing go with Dash or Beaner's info.

http://www.filehelpers.com/

user1231231412
  • 1,659
  • 2
  • 26
  • 42