MathGroup Archive 2006

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

Search the Archive

RE: Strings to Integers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67612] RE: [mg67566] Strings to Integers
  • From: "Erickson Paul-CPTP18" <Paul.Erickson at Motorola.com>
  • Date: Sun, 2 Jul 2006 06:27:27 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

I don't know about "smart" and further not exactly sure this is what
you're after, but ...

In[1]:=
timeList = {"12:33","120:03", "343:59","1:00" }

Out[1]=
{12:33,120:03,343:59,1:00}

In[2]:=
timeList // FullForm

Out[2]//FullForm=
List["12:33","120:03","343:59","1:00"]

In[3]:=
timeList // StringSplit[ #, ":"  ] & // ToExpression

Out[3]=
{{12,33},{120,3},{343,59},{1,0}}

In[4]:=
FullForm [%]

Out[4]//FullForm=
List[List[12,33],List[120,3],List[343,59],List[1,0]]

If not obvious the StingSplit changes each time string into a list of
two strings and the ToExpression converts to numbers.

Paul 

-----Original Message-----
From: Virgil Stokes [mailto:vs at it.uu.se] 
To: mathgroup at smc.vnet.net
Subject: [mg67612] [mg67566] Strings to Integers

The following is an example of a list that contains times in min:sec,

{12.33, 120:03, 343:59, 1:00}

where each element is of String type.

Is there a "smart" way to convert lists such as this into Integer type
for both minutes and seconds?

--Thanks,
V. Stokes


  • Prev by Date: Re: Re: Limit of an expression?
  • Next by Date: RE: SetOptions for Notebooks
  • Previous by thread: Re: Strings to Integers
  • Next by thread: Re: Re: Strings to Integers