This works. It returns "acb".
StringForm["a``b", "c"]
This doesn't work.
Export["test.txt", StringForm["a``b", "c"]]
Rather than "acb", test.txt
contains the literal expression StringForm["a``b", "c"]
.
This doesn't work either - it's the same result.
Export["test.txt", Evaluate[StringForm["a``b", "c"]]]
How can I force Mathematica to perform the StringForm
?
Export["test.txt", ToString @ StringForm["a``b", "c"]]
, but things will get ugly very quickly if the second argument of StringForm has things like 1/2 or 1.2*^-6. $\endgroup$StringTemplate
is a better choice in this case. $\endgroup$StringTemplate
, e.g., things likeStringTemplate["first `a` then `b`"][<|"a"->1/2, "b"->1.2*^-77|>]
produce output that I consider very suboptimal. $\endgroup$ToString[StringForm[a,b]]
seems to behave very strangely ifb
contains newlines (which my use case does). E.g. I'd expectToString[StringForm["AAA``BBB", "CCC\nDDD"]]
to return "AAACCC\nDDDBBB", but it actually returns "AAACCCBBB\n\ \ \ DDD". (Wrong letter order, extra whitespace.)StringForm["AAA``BBB", "CCC\nDDD"]
alone behaves as expected. $\endgroup$First@ToBoxes@StringForm["AAA``BBB", "CCC\nDDD"]
$\endgroup$