how to write string to file without Quotation mark

I am trying to Write String to file, something like this:

Write["test.txt", "This is a test"];


when I opened the file I found that the string was written with the Quotation mark " like this:

"This is a test"

how can I write only the string text?

Note: "This is a test" is part of matrix and I can't manually type it like this:

Write["test.txt", This is a test];

• Try Export instead of Write. – seismatica Jul 16 '14 at 8:43
• Does not help because Export overwrite the file. I am using continues writing to the file using OpenAppend – Basheer Algohi Jul 16 '14 at 8:48
• Related: (648), (5585), (41047) – Mr.Wizard Jul 16 '14 at 10:12
• Can't you use Export["test.txt","This is a test","Text"] – Eric William Smith Mar 16 '17 at 18:44

one way:

 SetDirectory[NotebookDirectory[]];
fileName = "test.txt";
file = OpenWrite[fileName, PageWidth -> Infinity];
WriteString[file,"this is a string which will show up without the quotes"];
Close[file]


To open for append and lines:

SetDirectory[NotebookDirectory[]];
fileName = "AAA.txt";
file = OpenAppend[fileName, PageWidth -> Infinity];
WriteString[file, "this is a string which will show up without the quotes\n"];
WriteString[file, "second line\n"];
Close[file]


important: must add "\n" at the end of the string. Without it, all string will remain on same line.

You can also in the notebook, add the new line, and will be be reflected in the file. Like this:

Notice, in the above there is no explicit "\n" there, but it was added in the notebook. The above will look like this in the text file:

• Great. Thanks a lot. – Basheer Algohi Jul 16 '14 at 9:02
• One thing I want to add, the text I am writing is an element in big list. you would agree if instead of adding "\n" to the end of the text, I can add WriteString["AAA.txt", "\n"]; after what I want to write. – Basheer Algohi Jul 16 '14 at 9:06
• @Algohi First, it is WriteString[file, "\n"] where file is the file handle returned from the OpenAppend call. Second, yes, you can do "\n" on its own, it will go to the end of the last written string and make new line. WriteString does not add "\n" on its own. The user has control on that. You can write WriteString[file,"A\nB\n"] if you want. – Nasser Jul 16 '14 at 9:09

Addressing the comment, WriteString can take multiple arguments to write multiple expressions so you can do:

 WriteString[file, "string" , "\n" ]


which may be somewhat more convenient than concatenating the "\n" to the string.

If you want to write a list of strings adding linebreaks you can do like this:

 WriteString[f,
Sequence @@ Riffle[{"string1", "string2", "String3"}, "\n"], "\n"]