MathGroup Archive 2001

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

Search the Archive

Re: Converting from string to integer and back

  • To: mathgroup at smc.vnet.net
  • Subject: [mg29044] Re: [mg29030] Converting from string to integer and back
  • From: BobHanlon at aol.com
  • Date: Sat, 26 May 2001 21:53:34 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

To convert a Number to a String use ToString and to convert back use 
ToExpression.  However, there are more direct approaches to do what you want.

partitionDate1[d_Integer] := 
    FromDigits /@ (Take[IntegerDigits[d], #]& /@ {4, {5, 6}, -2});

partitionDate1[20010525]

{2001, 5, 25}

partitionDate2[d_Integer] := {IntegerPart[d/10000], 
      IntegerPart[Mod[d, 10000]/100], Mod[d, 100]};

partitionDate2[20010525]

{2001, 5, 25}


Bob Hanlon

In a message dated 2001/5/25 2:07:14 AM, polar at cloud9.net writes:

>Is there an easy way to convert an integer to a string and then back to
>an integer?  I have a file containing dates in the YYYYMMDD format.  I
>want to convert these dates to {YYYY, MM, DD} so that I can some of the
>functions in the misc`Calendar package.  But at this point I am lost as
>to how to split the date into year,month, day.  StringTake is the only
>way I could think of but doesn't work as the head of the date is
>integer.  If there was a way to convert the date to a string I can split
>the date and then convert this back to an integer but I have seen no
>treatment of anything like this in the books I have.  I guess I'm a
>little more used to handling text in perl.  Any help while I'm riding up
>the learning curve is greatly appreciated.


  • Prev by Date: Re: Plot[f[x], {x,a,b}] Not Reaching End Points
  • Next by Date: Re: ColorFunction for ListPlot3D, ListContourPlot or ListDensityPlot ?
  • Previous by thread: Re: Converting from string to integer and back
  • Next by thread: Re: Converting from string to integer and back