MathGroup Archive 2001

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

Search the Archive

Re: String to Number

  • To: mathgroup at smc.vnet.net
  • Subject: [mg27171] Re: [mg27156] String to Number
  • From: Helge Andersson <helgea at inoc.chalmers.se>
  • Date: Fri, 9 Feb 2001 03:10:19 -0500 (EST)
  • References: <200102080940.EAA22639@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com


steffenz at server2.fo.FH-Koeln.DE wrote:

> 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

Hello Steffen,
Here are some solutions:

In[11]:=
str = {"06:42", "07:56", "11:23"};
pos = {2, {4, 5}};
li = Flatten[Table[{i, #} & /@ {pos[[1]], pos[[2]]}, {i, 1,
Length[str]}], 1];

In[34]:=
newvars1 = Partition[ToExpression[StringTake[str[[#1]], #2]] & @@@ li,
2];

newvars2 =
  Table[#1[#2[#3, pos[[j]]]], {j, 1, 2}] &[ToExpression, StringTake,
        str[[#]]] & /@ {1, 2, 3};

newvars3 =
    Partition[
      Map[StringTake, Sequence @@ {str[[#1]], #2} &] @@@ li //
ToExpression,
      2];


In[37]:=
Scan[Print, {li, newvars1, newvars2, newvars3}]

{{1, 2}, {1, {4, 5}}, {2, 2}, {2, {4, 5}}, {3, 2}, {3, {4, 5}}}

{{6, 42}, {7, 56}, {11, 23}}

{{6, 42}, {7, 56}, {11, 23}}

{{6, 42}, {7, 56}, {11, 23}}

Helge Andersson
Environmental Inorganic Chemistry
Chalmers
SE-412 96 Göteborg

Tel. 031-772 8072
Fax 031-772 2853




  • Prev by Date: RE: String to Number
  • Next by Date: Solving a system of nonlinear equations containing integrals
  • Previous by thread: Re: String to Number
  • Next by thread: Re: String to Number