# StringJoin with Spaces

I'm having some trouble using StringJoin --- the problem is that the StringJoin function creates a string where all the words in a list are combined without any spaces (whitespace)

For instance, list = {"hi","how","are","you"} StringJoin[list] will give me hihowareyou What do I have to do to get hi how are you as one string?

Another option is to use ListFormat

  TextString[list, ListFormat -> {"", "    ", ""}]


gives

   "hi    how    are    you"

• Thank you for this! All of the answers here worked but I found this to be the simplest Oct 13 '17 at 16:33

In M10.1+ you can use StringRiffle:

StringRiffle[
{"hi","how","are","you"},
" "
] //InputForm


"hi how are you"

The Map function will "do the same thing" to every element in a list. So we use that to StringJoin a space onto the end of every word in your list, except the last word. And then we Use StringJoin on that plus the last word in your list to put all those together into a single string. So

list = {"hi", "how", "are", "you"};
StringJoin[Map[StringJoin[#, " "]&, Most[list]], Last[list]]


which gives you the string "hi how are you"