RE: String to Number
- To: mathgroup at smc.vnet.net
- Subject: [mg27190] RE: [mg27156] String to Number
- From: "David Park" <djmp at earthlink.net>
- Date: Fri, 9 Feb 2001 03:10:35 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Steffen,
If the string is always in the form "mm:ss" you could do this:
str = "06:42"
{minutes, seconds} = ToExpression /@ {StringTake[str, 2],
StringTake[str, -2]}
{6, 42}
If the minutes could go beyond 99 and the seconds could have a decimal
point, and there is always one and only one colon, then you could use this.
toMinutesSeconds[str_] :=
With[{poscolon = StringPosition[str, ":"][[1,1]]},
ToExpression /@ {StringTake[str, poscolon - 1],
StringDrop[str, poscolon]}]
str2 = "124:23.456"
{minutes, seconds} = toMinutesSeconds[str2]
{124, 23.456}
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
> From: steffenz at server2.fo.FH-Koeln.DE
To: mathgroup at smc.vnet.net
> [mailto:steffenz at server2.fo.FH-Koeln.DE]
> Subject: [mg27190] [mg27156] String to Number
>
> Hi
>
> I read a time from a file (this format 06:42) as a string.
>
> I would like to convert this string into to numbers (6 and 42).
>
> any suggestions?
>
> Thanks
>
> Steffen
>
>
> Dipl.-Ing. Steffen Zozgornik
>
> Institut fur Licht- und Bautechnik
> an der Fachhochschule Koeln
> Gremberger Strasse 151 a
> D - 51105 Koeln
>
> Tel.: +49 - 221 - 83 10 95
> Fax.: +49 - 221 - 83 55 13
>
>
>