# Getting a String from a list of strings

Is there a way to write down Mathematica with a string such as:
{"M","a","t","h","e","m","a","t","i","c","a"}?

-
?*String* will list the available string functions if you need more information. – image_doctor Jun 19 '12 at 19:47

## 6 Answers

Supporting the maxim "there is always another way to do it":

list = {"M","a","t","h","e","m","a","t","i","c","a"};


StringJoin accepts lists directly, and in fact is faster this way:

StringJoin @ list

"Mathematica"


Also, StringJoin has the short form <> therefore you could also use:

"" <> list

"Mathematica"


Speed check:

large = Characters@ExampleData[{"Text", "LoremIpsum"}];

Do[StringJoin @@ large, {5000}] // Timing

Do["" <> large, {5000}] // Timing

{1.528, Null}

{0.671, Null}

-
Good maxim :) You and Jagra seem to have the same one :) – Öskå Jun 19 '12 at 19:21
""<> list ...Elegant! – Jagra Jun 19 '12 at 19:24
@Öskå Jagra's answer shows something else: it would still work if StringJoin could only accept two strings. Fold is a very useful function to know. See my example here. – Mr.Wizard Jun 19 '12 at 19:25
@Jagra thanks :D – Mr.Wizard Jun 19 '12 at 19:25
Brilliant. I definitely need to get used with # and @@ and & and such things, is there a good "course" about this on S.E.? – Öskå Jun 19 '12 at 19:36

Use StringJoin:

StringJoin @@ {"M", "a", "t", "h", "e", "m", "a", "t", "i", "c", "a"}


"Mathematica"

-
ah, been looking for one hour. Feels dumb Thanks! – Öskå Jun 19 '12 at 18:41
No problem, we've all experienced the same thing, good luck. – image_doctor Jun 19 '12 at 18:42

Just for something different Fold works too:

Fold[#1 <> #2 &, "", {"M", "a", "t", "h", "e", "m", "a", "t", "i",
"c", "a"}]

"Mathematica"

-

If we're going to get silly about it:

TextRecognize @ Graphics @ MapIndexed[Text[Style[#1, 50], {#2[[1]], 0}] &, list]

-

At risk of taking "even more" too far here is a method that does not use any function with "String" in the name:

list = {"M", "a", "t", "h", "e", "m", "a", "t", "i", "c", "a"};

FromCharacterCode @ Flatten @ ToCharacterCode @ list


Or using an export function:

ExportString[{list}, "Table", "FieldSeparators" -> ""]


Or a formatting function:

ToString @ Row @ list

-
Sheer vulpinism, that's what it is :) – István Zachar Jun 19 '12 at 21:37
+1 for: 'ToString @ Row @ list'. This seems to me the most interesting of all the solutions offered for the question, because you've taken such an original view of the problem while maintaing your customary clarity and conciseness. Nice! – Jagra Jun 20 '12 at 14:03

Just to stretch even more the limits of "there is always another way to do it" (Mr.Wizard), here is a way to NOT use StringJoin at all:

chars = {"M", "a", "t", "h", "e", "m", "a", "t", "i", "c", "a"};
Fold[StringInsert[#1, #2, -1] &, "", Flatten@chars]

"Mathematica"


And a simpler one:

StringExpression @@ chars


Using built-in path functions to complicate things (use ToFileName if prior to version 7):

StringReplace[FileNameJoin@chars, "\\" -> ""]

-