[Date Index] [Thread Index] [Author Index]
Re: StringForm bug?
pdickof at scf.sk.ca wrote: > I create a form... > > myForm = " Line `1`\n > Line `2`\n > Line `3`" > > Executing the StringForm line below gives me what I expect and want... > > StringForm[myForm, 1, 2, 3] > > but if I try to create an ordinary String from the StringForm object... > > InputForm[ToString[StringForm[myForm, 1, 2, 3]]] > > ... I get... > > " Line 1 2 3\n Line Line " > > Which is apparently wrong and certainly not what I want. How do I get > this to work? > I am running Mathematica 5.2 > > Thanks in advance. > Peter Dickof > Hi, I am not sure I would classify this as a bug, but if you look at the help for StringForm, it says "StringForm acts as a wrapper, which affects printing, but not evaluation." This seems to be Wolfram-speak for "Useful as a wrapper for printing, but nothing else!" These wrappers - such as MatrixForm - often get left in expressions that are used elsewhere, and they cause a lot of mischief! In this case, there is no reason to expect ToString to operate usufully on your StringForm - and it doesn't! I would use StringReplace to achieve what you want to do. The replacements must be strings - but you can use ToString to achieve that. David Bailey http://www.dbaileyconsultancy.co.uk