MathGroup Archive 2001

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

Search the Archive

Re: String to Number

  • To: mathgroup at smc.vnet.net
  • Subject: [mg27221] Re: [mg27156] String to Number
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Mon, 12 Feb 2001 03:20:59 -0500 (EST)
  • References: <200102080940.EAA22639@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

I presume you want to delete the zero both in the hours and in the minutes,
when they are less than 10, right? Suppose, then, you read the string in the
format hh:mm.
The following function will do what you want:

In[1]:=
makeNumbers[x_String] :=
  ToExpression[{If[StringTake[x, 1] == "0", StringTake[x, {2}],
        StringTake[x, 2]],
      If[StringTake[x, 3] == "0", StringTake[x, {-2}], StringTake[x, -2]]}]

In[2]:=
makeNumbers["06:42"]
Out[2]=
{6, 42}
In[3]:=
makeNumbers["12:28"]
Out[3]=
{12, 28}
In[4]:=
makeNumbers["12:03"]
Out[4]=
{12, 3}

Tomas Garza
Mexico City
----- Original Message -----
From: <steffenz at server2.fo.FH-Koeln.DE>
To: mathgroup at smc.vnet.net
Subject: [mg27221] [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
>
>



  • Prev by Date: RE: Using Different Kinds of Characters With Do?
  • Next by Date: Problems in rendering Graphics3D with RealTime3D (Mathematica 4.1)
  • Previous by thread: Re: String to Number
  • Next by thread: Re: String to Number