Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I know this is a simple question and there is a single command to do this but I have been looking for the command for 30+ minutes and cannot find it. I have a list that I want to put tabs between columns and new lines between rows. As a simple example, I have a list

  list = {{1, 2, 3}, {a, b, c}}

and I want to convert it to the string

  "1\t2\t3\na\tb\tc"
share|improve this question

closed as off-topic by Pickett, rasher, Mr.Wizard Jul 13 at 23:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Pickett, rasher, Mr.Wizard
If this question can be reworded to fit the rules in the help center, please edit the question.

3 Answers 3

up vote 6 down vote accepted

Using ExportString:

ExportString[list, "TSV"]

If you want to make sure it's right:

ExportString[list, "TSV"] // InputForm
share|improve this answer

I know this is a simple question and there is a single command to do this but I have been looking for the command for 30+ minutes and cannot find it.

Let's address that. In either version 7 or version 10 searching the documentation for:

convert table to string

brings up ImportString as one of the first results; 2nd in v10, and 5th in v7.
In that documentation the first example is:

In[1]:= ImportString["3,4,6\na,b,c", "Table"]

Out[1]= {{"3,4,6"}, {"a,b,c"}}

This is quite similar to your operation but in reverse, so you should keep reading, which leads to:

SEE ALSO
Export ExportString Import . . .

This should have at least narrowed your search to the right area.

I hope this helps improve your use of the documentation system in the future.

share|improve this answer

Try something like this:

tb = Table["\t", {i, Length[list[[1]]]}]; 
Join[Transpose[{ToString /@ #1[[1]], #2}], 
    Transpose[{ToString /@ #1[[2]], #2}]] &[list, tb] // StringJoin
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.