Re: Decompose string into list
- To: mathgroup at smc.vnet.net
- Subject: [mg64089] Re: [mg64079] Decompose string into list
- From: "David Annetts" <davidannetts at aapt.net.au>
- Date: Wed, 1 Feb 2006 04:34:20 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Hi Renan, > I can make a string from a list, using: > > In[1]:= StringJoin @@ {"F", "o", "o", " ", "b", "a", "r"} > Out[1]:= Foo bar > > But I want to "decompose" a string into a list composed by > its elements, e.g. > > "Foo bar" turns back into {"F", "o", "o", " ", "b", "a", "r"} > "Hello" turns back into {"H","e","l","l","o"}. > > How to do this? Mathematica 5.2 on Windows. One approach is to iterate over the length of the string, appending each of its elements to a list, eg str = "Hello"; StringTake[str, {#}] & /@ Range[StringLength@str] Another is to use StringSplit. StringSplit["Hello", ""] StringSplit["Foo bar", ""] Regards, Dave.