Re: String to List

*To*: mathgroup at smc.vnet.net*Subject*: [mg77015] Re: String to List*From*: Bill Rowe <readnewsciv at sbcglobal.net>*Date*: Thu, 31 May 2007 03:39:44 -0400 (EDT)

On 5/30/07 at 5:36 AM, peter.king at imperial.ac.uk (King, Peter R) wrote: >I have a string which in general looks something like >a="{x,16,x,1T,x}" >In other words it looks like a list with a mixture of characters and >numbers and so on. I want to pick out the individual elements of >this (using the commas as delimiters) >I can do b=ToExpression[a] and I get a list so b[[1]] is x and >b[[2]]=16 (that is the number sixteen but I can convert this back >into = a string with ToString. The problem is b[[4]] which >ToExpression turns into T as it thinks I mean 1 x T. >So I would appreciate help with either >i) converting my original string to a list as I would like This is easily done using StringSplit, i.e. In[1]:= a = "{x,16,x,1T,x}"; b = StringSplit[StringTake[a, {2, -2}], ","] Out[2]= {x,16,x,1T,x} In[3]:= b[[4]] Out[3]= 1T -- To reply via email subtract one hundred and four