1

Is there a way to use string.Join to create a tab-delimited string and output that into a file?

I'm doing this:

string.Join(@"\t", array);

But in my file (I've tried .txt and .csv), the results are as such:

one\ttwo\tthree\tfour\tfive

I assume it's because the delimiter isn't a standard one-character delimiter because it works perfectly fine using pipes or commas.

I know there are many other ways this can be done but I was hoping to create a one-size-fits-all solution using string.Join which may just not be possible.

Thanks!

Danny Lager
  • 371
  • 1
  • 4
  • 17

2 Answers2

5

You are using verbatim string @"\t" instead of a regular string. Use "\t".

See MSDN and SO for reference.

Community
  • 1
  • 1
Piotr Falkowski
  • 1,957
  • 2
  • 16
  • 24
1

Just came across the same problem and string.Join("\t", array) didn't work for me.

string.Join(Constants.vbTab, array) did the job for me.

bautista
  • 765
  • 10
  • 26