ToString

ToString[expr]

gives a string corresponding to the printed form of expr in OutputForm.

ToString[expr,form]

gives the string corresponding to output in the specified form.

Details and Options

Examples

open allclose all

Basic Examples  (2)

Give a string corresponding to the OutputForm of x2:

Give a string corresponding to the InputForm:

Scope  (2)

Strings for OutputForm, InputForm, StandardForm, and TraditionalForm of an expression:

Non-default character encoding:

Options  (4)

CharacterEncoding  (1)

Generate a string using the default encoding:

Use ASCII encoding instead:

FormatType  (1)

Use FormatType to change the formatting:

NumberMarks  (1)

Use the default setting of InputForm formatting:

Explicitly set whether number marks should be included:

PageWidth  (1)

By default, the page width is infinite:

Wrap to a new line after 9 characters in the string:

Applications  (2)

Construct an indexed set of variables:

Export data to files with programmatically created names:

Properties & Relations  (3)

Use ToExpression to convert strings or boxes to expressions:

Use ToBoxes to convert expressions to boxes:

Use ToString with ToExpression to convert TeX to Wolfram Language syntax:

ToString uses definitions from Format and MakeBoxes:

Possible Issues  (1)

ToString by default uses OutputForm formatting:

Specify other formats to preserve styling information:

Wolfram Research (1988), ToString, Wolfram Language function, https://reference.wolfram.com/language/ref/ToString.html (updated 1996).

Text

Wolfram Research (1988), ToString, Wolfram Language function, https://reference.wolfram.com/language/ref/ToString.html (updated 1996).

BibTeX

@misc{reference.wolfram_2021_tostring, author="Wolfram Research", title="{ToString}", year="1996", howpublished="\url{https://reference.wolfram.com/language/ref/ToString.html}", note=[Accessed: 28-October-2021 ]}

BibLaTeX

@online{reference.wolfram_2021_tostring, organization={Wolfram Research}, title={ToString}, year={1996}, url={https://reference.wolfram.com/language/ref/ToString.html}, note=[Accessed: 28-October-2021 ]}

CMS

Wolfram Language. 1988. "ToString." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 1996. https://reference.wolfram.com/language/ref/ToString.html.

APA

Wolfram Language. (1988). ToString. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ToString.html