({{, (RefLink[TextString, paclet:ref/TextString])[expr] 
gives a human-readable string representation of expr.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[TextString, paclet:ref/TextString]) converts expressions to a single string, formatting expressions with the following heads specially:

(RefLink[TextString, paclet:ref/TextString])[(RefLink[Row, paclet:ref/Row])[list]] formats as a concatenation of elements of list.

(RefLink[TextString, paclet:ref/TextString])[(RefLink[Row, paclet:ref/Row])[list,sep]] uses separator sep to combine formatted elements.

(RefLink[TextString, paclet:ref/TextString])[(RefLink[Column, paclet:ref/Column])[list]] formats each element on a separate line.

(RefLink[TextString, paclet:ref/TextString])[(RefLink[TableForm, paclet:ref/TableForm])[list]] formats a list of lists as space-separated columns.

Expressions that match patterns in the list given as the setting for (RefLink[ElidedForms, paclet:ref/ElidedForms]) are formatted in an elided way.

In other cases, expressions are formatted using (RefLink[InputForm, paclet:ref/InputForm]).

(RefLink[TextString, paclet:ref/TextString]) supports the following options:

OpenersPrimaryExamplesSection(Spacer1)Examples  (15)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Convert an integer:

TextString[10]//InputForm

Convert a real number:

TextString[10.]//InputForm

Convert a (RefLink[GeoPosition, paclet:ref/GeoPosition]):

TextString[Here]//InputForm

Convert a (RefLink[DateObject, paclet:ref/DateObject]):

TextString[Now]//InputForm

Convert a (RefLink[TimeObject, paclet:ref/TimeObject]):

TextString[Today]//InputForm

Convert a (RefLink[Quantity, paclet:ref/Quantity]):

TextString[Quantity[3,"Joules"]]//InputForm

Convert a list of elements:

TextString[{Yesterday,Today,Tomorrow}]//InputForm

OpenersExampleSection1(Spacer1)Scope  (4)

By default, (RefLink[TextString, paclet:ref/TextString]) converts certain built-in expressions to an elided string:

TextString[RandomImage[]]//InputForm

(RefLink[TextString, paclet:ref/TextString]) recurses arbitrarily through lists and associations to convert an expression:

TextString[{{1,2},{3,4,5},<|a->{b,6,7}|>}]//InputForm

Typically, expressions that satisfy (RefLink[NumericQ, paclet:ref/NumericQ]) are formatted as real numbers:

TextString[{1/2,Sqrt[2],Exp[3]}]//InputForm

(RefLink[Row, paclet:ref/Row]) formats as a concatenation of its contents:

TextString[Row[{"a","b","c","d"}]]//InputForm

(RefLink[Column, paclet:ref/Column]) formats each element on a new line:

TextString[Column[Range[5]]]

(RefLink[TableForm, paclet:ref/TableForm]) formats elements as a table in which columns are space-separated:

TextString[TableForm[RandomInteger[1000,{10,5}]]]

OpenersExampleSection2(Spacer1)Options  (6)

OpenersExampleSubsection0(Spacer1)AssociationFormat  (1)

By default, (RefLink[TextString, paclet:ref/TextString]) formats associations as they normally appear in the Wolfram Language:

TextString[<|a->1,b->2|>]//InputForm

Use different delimiters:

TextString[<|a->1,b->2|>,AssociationFormat->{"{",", ","}",":"}]//InputForm

OpenersExampleSubsection1(Spacer1)BooleanStrings  (1)

By default, the symbols (RefLink[True, paclet:ref/True]) and (RefLink[False, paclet:ref/False]) format as themselves:

TextString[{True,False,True,True}]//InputForm

Specify different strings to use for the symbols (RefLink[True, paclet:ref/True]) and (RefLink[False, paclet:ref/False]):

TextString[{True,False,True,True}, BooleanStrings -> {"✓","×"}]//InputForm

OpenersExampleSubsection2(Spacer1)DateFormat  (1)

(RefLink[TextString, paclet:ref/TextString]) uses the same default format as (RefLink[DateString, paclet:ref/DateString]):

TextString[{Today,Tomorrow}]//InputForm

Override the default date format:

TextString[{Today,Tomorrow},DateFormat->{"Year","-", "Month","-","Day"}]//InputForm

OpenersExampleSubsection3(Spacer1)ElidedForms  (1)

The default value (RefLink[ElidedForms, paclet:ref/ElidedForms])->(RefLink[Automatic, paclet:ref/Automatic]) elides certain complex symbolic expressions:

TextString[RandomImage[],ElidedForms->Automatic]//InputForm

Ordinary symbolic expressions are formatted normally:

TextString[{f[10],g[20],h[30]}]//InputForm

Elide specific symbolic expressions:

TextString[{f[10],g[20],h[30]},ElidedForms->{f,h}]//InputForm

Elide all symbolic expressions for which specific formatting rules do not exist:

TextString[{f[10],g[20],h[30]},ElidedForms->All]//InputForm

OpenersExampleSubsection4(Spacer1)ListFormat  (1)

By default, (RefLink[TextString, paclet:ref/TextString]) formats lists as they normally appear in the Wolfram Language:

TextString[{1,2,3,4}]//InputForm

Use different delimiters:

TextString[{1,2,3,4},ListFormat->{"[",", ","]"}]//InputForm

OpenersExampleSubsection5(Spacer1)MissingString  (1)

By default, expressions with head (RefLink[Missing, paclet:ref/Missing]) are ignored:

TextString[{1,2,Missing[]}]//InputForm

Specify a different string:

TextString[{1,2,Missing[]},MissingString->"?"]//InputForm

Use the given reason, if available:

TextString[{1,2,Missing["NotAvailable"]}, MissingString->Automatic]//InputForm

OpenersExampleSection3(Spacer1)Properties & Relations  (1)

(RefLink[UpValues, paclet:ref/UpValues]) can be defined for custom objects to determine how they should be formatted by (RefLink[TextString, paclet:ref/TextString]):

quoted /: TextString[quoted[str_]] := "\"" <> str <>"\"";

TextString[{1,2,quoted["foo"], 3, 4}]

OpenersExampleSection4(Spacer1)Possible Issues  (1)

Nesting (RefLink[Row, paclet:ref/Row]) and (RefLink[Column, paclet:ref/Column]) expressions does not produce a table:

TextString@Row[{Column[{1,3}],Column[{2,4}]}]

Use (RefLink[TableForm, paclet:ref/TableForm]) to produce a table:

TextString@TableForm[{{1,3},{2,4}}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[ToString, paclet:ref/ToString])  ▪  (RefLink[StringTemplate, paclet:ref/StringTemplate])  ▪  (RefLink[InputForm, paclet:ref/InputForm])  ▪  (RefLink[OutputForm, paclet:ref/OutputForm])  ▪  (RefLink[Short, paclet:ref/Short])  ▪  (RefLink[WriteString, paclet:ref/WriteString])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Converting between Expressions & Strings, paclet:guide/ConvertingBetweenExpressionsAndStrings])}, {▪(RefLinkPlain[Text Generation, paclet:guide/TextConstruction])}, {▪(RefLinkPlain[Text Manipulation, paclet:guide/ProcessingTextualData])}, {▪(RefLinkPlain[String Manipulation, paclet:guide/StringManipulation])}, {▪(RefLinkPlain[Notebook Document Generation, paclet:guide/DocumentGeneration])}, {▪(RefLinkPlain[Working with Templates, paclet:guide/WorkingWithTemplates])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(WebLink[DocumentationFooterIconsRelatedLinks-EIWL.png(Spacer1)An Elementary Introduction to the Wolfram Language, https://www.wolfram.com/language/elementary-introduction/42-string-patterns-and-templates.html])(WebLink[: String Patterns and Templates , https://www.wolfram.com/language/elementary-introduction/42-string-patterns-and-templates.html])}})}})