Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: String to List

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

On 5/30/07 at 5:36 AM, peter.king at (King, Peter R)

>I have a string which in general looks something like


>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

  • Prev by Date: Re: links for 6!
  • Next by Date: Re: v6: cursor behaviour with arrow keys
  • Previous by thread: Re: String to List
  • Next by thread: Re: String to List