MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: String to List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77210] Re: String to List
  • From: fiaminamor at gmail.com
  • Date: Tue, 5 Jun 2007 07:00:46 -0400 (EDT)
  • References: <f3jigv$dpo$1@smc.vnet.net>

On May 30, 5:09 am, "King, Peter R" <peter.k... at imperial.ac.uk> 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)

Mathematica has built in commands to parse structured text like that.
Look up ReadList, RecordSeparators, and WordSeparators in the
Mathematica book.  I tried it in Mathematica 5.2 and it worked.

In[1]:= a = "{x,16,x,1T,x}"

In[2]:= ReadList[ StringToStream[a],
                  Word,
                  RecordSeparators -> { {"{"}, {"}"} },
                  WordSeparators -> ","
                ] //InputForm

Out[2]//InputForm= {"x", "16", "x", "1T", "x"}





  • Prev by Date: Inverse, numerical precision, simulation dynamical system
  • Next by Date: links
  • Previous by thread: Re: Re: String to List
  • Next by thread: NestListEffects function not working in 6.0