Re: String to Number
- To: mathgroup at smc.vnet.net
- Subject: [mg27274] Re: [mg27156] String to Number
- From: steffenz at server2.fo.FH-Koeln.DE
- Date: Fri, 16 Feb 2001 03:58:23 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Dear Tomas, thank You for Your function, but the zeros are "deleted" automatically after conversion into a number. Steffen > Date: Thu, 08 Feb 2001 12:31:51 -0600 > From: Tomas Garza <tgarza01 at prodigy.net.mx> To: mathgroup at smc.vnet.net > Subject: [mg27274] Re: [mg27156] String to Number > To: steffenz at server2.fo.FH-Koeln.DE > Cc: mathgroup at smc.vnet.net > 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 > To: <mathgroup at smc.vnet.net> > Sent: Thursday, February 08, 2001 3:40 AM > Subject: [mg27274] [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 > > > > > > Dipl.-Ing. Steffen Zozgornik Institut für Licht- und Bautechnik an der Fachhochschule Köln Gremberger Straße 151 a D - 51105 Köln Tel.: +49 - 221 - 83 10 95 Fax.: +49 - 221 - 83 55 13