MathGroup Archive 2005

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

Search the Archive

Re: Converting Strings to Ints.


"Chrisantha" <ctf20 at sussex.ac.uk> a écrit dans le message de news: 
dode99$64c$1 at smc.vnet.net...
| Dear All,
|
| I have a list of strings representing numbers, i.e. a =
| {"12223","11313","2424"} that I generated in XML and read into
| mathematica. How do I convert this into a list of integers?
|
| Yours Ever and Merry Christmas,
|
| Chrisantha
|

Hi Chrisantha,

You can use the built-in function *ToExpression* (see In[4]):

In[1]:= lst = {"12223", "11313", "2424"}
Out[1]= {12223,11313,2424}

In[2]:= FullForm[lst]
Out[2]//FullForm= List["12223","11313","2424"]

In[3]:= Head /@ lst
Out[3]= {String,String,String}

In[4]:= data = ToExpression[lst]
Out[4]= {12223,11313,2424}

In[5]:= FullForm[data]
Out[5]//FullForm= List[12223,11313,2424]

In[6]:= Head /@ data
Out[6]= {Integer,Integer,Integer}

Best regards,
/J.M. 



  • Prev by Date: Re: Converting Strings to Ints.
  • Next by Date: Re: Returning an empty sequence
  • Previous by thread: Re: Converting Strings to Ints.
  • Next by thread: Re: Converting Strings to Ints.