# How to interpret a string as a multiline cell of expressions

I need a string like the following:

"2+2
\"Hello
world\"
3+3"


to be evaluate like

2+2
"Hello
world"
3+3


Note that ToExpression evaluates that string as

2+2;
"Hello
world";
3+3


that is that it prints only the last line.

If I understand your question correctly, the following code

str = "2+2
\"Hello
world\"
3+3";
ToExpression[str, InputForm, Print /@ List[##] &];


does what you want. Alternatively, you can use

ToExpression[str, InputForm, List]


and decide what to do with the list later. The documentation for ToExpression states:

ToExpression[input, form, h]

wraps the head h around the expression produced before evaluating it.

• Yes, thanks. I came to a similar solution: Print/@(List@@ToExpression[s, Inputform, Hold]). So, in general terms, how would you explain the role of the third argument of ToExpression ? and what is the default function ToExpression calls if the third argument is omitted? – Fortsaint Aug 26 at 22:57