# Joining Together Strings and variables [closed]

I am trying to join together strings and variables as part of formatting the output of my code. For example how do I print the line "5 trees" where the number 5 is a variable n that could be changing. I've tried the following, which doesn't work:

 n=5;
Print[n <> "trees"]


Any idea on how to get that to print as "5 trees"? Thanks!

• Print[n, " trees"] and take a look StringForm or Templates friends. – Kuba Apr 2 '15 at 19:55

For trivial combinations, simple Print combinations work well.

For more complex operations, take a look at StringForm:

var1 = "Tree";
var2 = 10;

StringForm["The 1 is about 2 feet tall...", var1, var2]

(* "The Tree is about 10 feet tall..." *)

n = 5;
Print[ToString[n] <> " trees"]