6
$\begingroup$

I have this: list=Range[1,4] and I want to Export the values in a text-file. But the values should be separated by a single empty space, like this:

in MMA[ {1,2,3,4} ] -> in txt-file[ 1 2 3 4 ]

How do I get extended control over the export options? Thanks for any hints!

$\endgroup$
10
$\begingroup$

Consult the ref/format/Table section of the documentation.

Using "Table" as the export format and specifying the option "FieldSeparators" -> " " you can get what you want:

ExportString[{Range[4]}, "Table", "FieldSeparators" -> " "]
(* 1 2 3 4 *)

Note that I've wrapped Range[] in a list like {Range[4]}, since each element at the top level is expected to be a row.

To have a more general control over the import and export options you can also try spelunking:

<<GeneralUtilities`
PrintDefinitions[Export]

After some searching there I found a function called System`Convert`TableDump`ExportTable which admits the options

"LineSeparators"
"FieldSeparators"
"TextDelimiters"
"TableHeadings"
CharacterEncoding
Alignment

You can either search around in this way if the documentation doesn't provide enough information or just roll your own export routine with the help of functions such as OpenWrite and others, when the built-in functionality isn't enough.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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