Re: Combining elements of a list
- To: mathgroup at smc.vnet.net
- Subject: [mg108847] Re: Combining elements of a list
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Sun, 4 Apr 2010 07:43:35 -0400 (EDT)
- References: <hp7735$krb$1@smc.vnet.net>
Hi,
> How could I go from:
> {h,e,l,l,o}
> to
> {hello}?
>
> That is the first step of what I am really looking to do. Which is
> to go from:
> {{t,h,i,s},{i,s},{a},{t,e,s,t},{m,e,s,s,a,g,e}}
> to
> "this is a test message"
>
If you want to join strings, use StringJoin :-)
this works if the entries are symbols:
letters={{t, h, i, s}, {i, s}, {a}, {t, e, s, t}, {m, e, s, s, a,
g, e}}
StringJoin[Riffle[Map[ToString,letters,{2}], " "]]
if the entries are strings already, this would be enough:
letters = {{"t", "h", "i", "s"}, {"i", "s"}, {"a"}, {"t", "e", "s",
"t"}, {"m", "e", "s", "s", "a", "g", "e"}}
StringJoin[Riffle[letters, " "]]
hth,
albert