Re: Strings to Integers
- To: mathgroup at smc.vnet.net
- Subject: [mg67701] Re: [mg67566] Strings to Integers
- From: Richard Palmer <mapsinc at bellatlantic.net>
- Date: Wed, 5 Jul 2006 04:17:50 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
I don't know how smart this is, but it will work. It seems to run at about the same speed as a program involving regular expressions. If you wish, you can turn it into a function or a one-liner. You have to do some more programming if you get more complex strings that have, say, fractions of a second, e.g. "42:33:12" First remove the colons (":") where they exist, and convert the strings into numbers 1) minssecs={12.33, 120:03, 343:59, 1:00} minssecs2=ToExpression[StringReplace[#, ":" -> "."]] & /@ minssecs Use IntegerPart and Mod to create the list you desire 2) answer={IntegerPart[#], Mod[#, 1]} & /@ minssecs2 First[answer[[I]]] is the mins for the ith time and Last[ans[[I]]] is the secs for the ith time. Regards, Richard Palmer \ On 7/1/06 5:11 AM, "Virgil Stokes" <vs at it.uu.se> wrote: > {12.33, 120:03, 343:59, 1:00}