Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

I'm trying to do something like below, but it doesn't work, since StringForm requires each item from parts to be given individually, and not in a list:

parts = ToString /@ {1, 2, 3};
(* this should be StringForm["`` `` ``", 1, 2, 3] and 
   not StringForm["`` `` ``", {1, 2, 3}] *)
StringForm["`` `` ``", parts]

I think this could be done with Flatten and Apply, but can I avoid using Apply? (looks ugly)

share|improve this question

marked as duplicate by Kuba, Sjoerd C. de Vries, Artes, Simon Woods, m_goldberg Oct 14 '13 at 12:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
How about: parts = Sequence @@ ToString /@ {1, 2, 3} –  RunnyKine Oct 14 '13 at 2:49
    
@RunnyKine Yep, that was exactly what I was looking for. I read about Sequence and tried using it, but I missed the @@ part –  Adal Oct 14 '13 at 3:15
    
@RunnyKine I notice you used @@ which is shorthand for Apply, which the OP wanted to avoid. –  Sjoerd C. de Vries Oct 14 '13 at 7:17
    
@SjoerdC.deVries I think OP meant Apply[f, expr] form. –  Kuba Oct 14 '13 at 7:25
    
@kuba In that case, StringForm["`` `` ``", ##]& @@ parts would be better IMHO. No need for Sequence. -- Oh, forget it, I just saw you already did that. –  Sjoerd C. de Vries Oct 14 '13 at 11:44

2 Answers 2

up vote 2 down vote accepted

How about:

 parts = Sequence @@ ToString /@ {1, 2, 3}
share|improve this answer

For StringForm you don't have to use ToString on arguments.

One way to avoid Apply, which was introduced to me by rm-rf, was to use Operate:

parts = {1, 2, 3};
StringForm["`` `` ``", Operate[Sequence &, parts]]
1 2 3

Also, if you want to use Apply in slightly different way than RunnyKine:

parts = {1, 2, 3};

StringForm["`` `` ``", ##] & @@ parts
1 2 3
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.