Prev: trying to use InputField as a continually attentive
Next: Finding order of all numbers in a Finite Field
From: ebaugh on 3 Apr 2010 06:59 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" Thanks all, Jason Ebaugh
From: Albert Retey on 4 Apr 2010 07:43 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
From: Harvey P. Dale on 4 Apr 2010 07:43 Jason: StringJoin@@ToString/@Flatten[Riffle[{{t,h,i,s},{i,s},{a},{t,e,s,t},{m,e ,s,s,a,g,e}}," "]] Best, Harvey -----Original Message----- From: ebaugh(a)illinois.edu [mailto:ebaugh(a)illinois.edu] Sent: Saturday, April 03, 2010 7:09 AM Subject: Combining elements of a list 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" Thanks all, Jason Ebaugh
From: Helen Read on 4 Apr 2010 07:43 On 4/3/2010 6:59 AM, ebaugh(a)illinois.edu wrote: > How could I go from: > {h,e,l,l,o} > to > {hello}? If you intend to treat the letters as characters (as opposed to symbols or expressions), you should enter them as strings, i.e., enclose them in quotes. Use StringJoin to concatenate strings. s1={"h","e","l","l","o"} StringJoin[s1] If you did not enter the characters as strings to begin with, you can convert them using ToString. a1={h,e,l,l,o} a2=Map[ToString,a1] StringJoin[a2] > 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" How are you generating the lists to begin with? It would probably be a lot easier to work with strings to begin with, instead of lists. However, working with what you have, here is a way to do it. I'll do it one step a time so you can see what each step does, with some (* comments *). b1 = {{t, h, i, s}, {i, s}, {a}, {t, e, s, t}, {m, e, s, s, a, g, e}} b2 = Map[ToString, b1, {2}] (* Map ToString accross b1 at the second level, to convert the letters to strings *) b3 = Table[" ", {n, Length[b2] - 2}] (* The Length of b2 is the number of words. We'll insert spaces in between words -- not on the ends -- so we need Length[b2] - 2 spaces. *) b4 = Riffle[b2, b3] (* riffle b2 and b3 to put the spaces in between the words *) b5 = Flatten[b4] (* remove the extra braces *) StringJoin[b5] (* concatenate the strings *) -- Helen Read University of Vermont
From: Hans Michel on 4 Apr 2010 07:44 Jason Ebaugh: You can try the following: In[16]:= phrase = {{"t","h","i","s"},{"i","s"},{"a"},{"t","e","s","t"},{"m","e","s","s","a","g","e"}} Out[16]= {{t,h,i,s},{i,s},{a},{t,e,s,t},{m,e,s,s,a,g,e}} In[17]:= StringJoin[Flatten[Riffle[phrase," "],Infinity]] Out[17]= this is a test message However, I am concerned about how will you arrive at {h,e,l,l,o} or even {{t,h,i,s},{i,s},{a},{t,e,s,t},{m,e,s,s,a,g,e}}. You are asking us to help solve this particular case/problem. But depending on how you arrived at this list in may be possible to avoid the trap alltogether. Hans <ebaugh(a)illinois.edu> wrote in message news:hp7735$krb$1(a)smc.vnet.net... > > 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" > > Thanks all, > Jason Ebaugh > > >
|
Next
|
Last
Pages: 1 2 3 Prev: trying to use InputField as a continually attentive Next: Finding order of all numbers in a Finite Field |