One of the little utility packages I use needs to convert Mathematica expressions to InputForm text that is interpolated into a custom file format which is then parsed by another tool. That other tool, for various reasons, has to actually parse the InputForm expressions, but uses its own parser to do so, and that parser doesn't deal very will with commas in Mathematica expressions. It will choke on something like this:
{{1, 2, 3}, {4, 5, 6}}
but works fine with this:
{{1,2,3},{4,5,6}}
By default, ToString, with the InputForm format, will stick spaces in after the commas. Currently, I use StringReplace to work around the problem:
stringifyForExport[form_] :=
StringReplace[
ToString[form, InputString, PageWidth -> Infinity,
CharacterEncoding -> "ASCII"],
" " -> ""];
I'm not very satisfied with this solution because it won't work if we have any strings in form that contain spaces. So far this hasn't caused serious problems, but I know it's just a matter of time. Is there a better way to get rid of those spaces?
Copy As...>Plain Textfor this? I believe that gives the format you want. – Mr.Wizard♦ May 17 '12 at 6:59