# Trouble with ToString and StringForm

The command

ToString[StringForm["SomeText= as well as OtherText=.", "textA", "textB"], FormatType -> InputForm]


produces the output

StringForm["SomeText= as well as OtherText=.", "textA", "textB"]


What I would like to produce instead is

"SomeText=textA as well as OtherText=textB"


The problem, of course disappears if I remove the FormatType->InputForm. However I need it, because StringForm otherwise produces a string which consistes of multiple lines if the parameters to StringForm are other objects like numerical values with exponents.

I tried various combinations with Hold and Evaluate, but could not change this behaviour to what I need.

fn[args__] :=
Replace[
StringForm[args],
x : Except[_String] :> ToString[x, InputForm],
1
] // ToString


Test:

fn["SomeText= as well as OtherText=.", 2.0*10^(-15), 2/5]

"SomeText=2.*^-15 as well as OtherText=2/5."

InputForm[
ToString@StringForm["SomeText= as well as OtherText=.", "textA", "textB"]]


"SomeText=textA as well as OtherText=textB."

If you have version 10 you might want to try StringTemplate

StringTemplate["SomeText= as well as OtherText=."]["textA", "textB"]


"SomeText=textA as well as OtherText=textB."

• InputForm[ ToString@StringForm["SomeText= as well as OtherText=.", 2.0*10^(-15), "textB"]] would however result in " -15\nSomeText=2. 10 as well as OtherText=textB." which is also not what I want. It should become "SomeText=2. 10^-15 as well as OtherText=textB." or similar. – highsciguy Apr 12 '15 at 19:44
• @highsciguy Couldn't you use ToString[2.0*10^(-15), InputForm] for your arguments? – Sjoerd C. de Vries Apr 12 '15 at 19:54
• Yes, I could. However, I would need to wrap every single number in my outputs with ToString then. – highsciguy Apr 12 '15 at 20:01