Re: Re: Strings to Integers
- To: mathgroup at smc.vnet.net
- Subject: [mg67634] Re: [mg67614] Re: [mg67566] Strings to Integers
- From: Bruce Colletti <vze269bv at verizon.net>
- Date: Mon, 3 Jul 2006 06:37:33 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Bob
I like your and Paul's solutions better than mine. The following baffles me, though...
Your solution delivers the desired list of integers:
ToExpression@StringSplit["12:00",":"]
Map[Head,%]
{12,0}
{Integer,Integer}
But why doesn't my solution work:
StringCases["12:00",x__~~":"~~y__->{ToExpression@x,ToExpression@y}]
Map[Head,%[[1]]]
{{12,00}}
{String,String}
I'm using v5.2.0.0. Thanks.
Bruce
=====================
From: Bob Hanlon <hanlonr at cox.net>
To: mathgroup at smc.vnet.net
Subject: [mg67634] [mg67614] Re: [mg67566] Strings to Integers
data = {"12:33", "120:03", "343:59", "1:00"};
ToExpression[StringSplit[#, ":"]& /@ data]
{{12, 33}, {120, 3}, {343, 59}, {1, 0}}
Bob Hanlon
---- Virgil Stokes <vs at it.uu.se> wrote:
> 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
>