MathGroup Archive 2006

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

Search the Archive

Re: Strings to Integers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67665] Re: Strings to Integers
  • From: albert <awnl at arcor.de>
  • Date: Tue, 4 Jul 2006 01:56:47 -0400 (EDT)
  • References: <e8as79$g61$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,
> 
> I like your and Paul's solutions better than mine.  The following baffles
> me, though...
> 
> Your solution delivers the desired list of integers:
> 
> ToExpression@StringSplit["12:00",":"]
> Map[Head,%]
> 
> {12,0}
> 
> {Integer,Integer}
> 
> But why doesn't my solution work:
> 
> StringCases["12:00",x__~~":"~~y__->{ToExpression@x,ToExpression@y}]

StringCases["12:00",x__~~":"~~y__:>{ToExpression@x,ToExpression@y}]

will do what you want. With -> you are evaluating ToExpression[y] before
even looking at the strings, which just gives y, only with :> you are
evaluating ToExpression["12"] and ToExpression["00"] which is what you
want..

hth,

albert


  • Prev by Date: Re: Position
  • Next by Date: Re: double line spacing in notebook
  • Previous by thread: Re: Re: Strings to Integers
  • Next by thread: Re: Strings to Integers