Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: atoi equivalents?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg99410] Re: atoi equivalents?
  • From: dbreiss at gmail.com
  • Date: Tue, 5 May 2009 05:41:25 -0400 (EDT)
  • References: <gtnk34$3le$1@smc.vnet.net>

>From the docs:

"ToExpression[input,form,Hold] can be used to convert input to an
expression, but with the expression wrapped in Hold to prevent
evaluation.  "

In this way the code in the hoped for number will not be arbitrarilly
executed.

Hope this helps,

David


On May 4, 4:44 pm, Michael <michael2... at gmail.com> wrote:
> What is the most efficient or recommended way to parse numbers in Mathematica?
>
> I can use ToExpression["1234"] and it will return the number.
> But this won't do, because I could be scraping un-trusted data and the
> above could lead to an injection of code.
> I could also use something like this: ToExpression[StringCases["1234",
> x1 : NumberString ~~ ___ -> x1]]
> but then I have to add error checking and whatnot.
> I suppose I could write a simple MathLink program which implement
> atoi, atol, etc.
>
> All of these solutions seems like a lot of overhead.  Anybody have a
> better idea?
>
> Thanks,
>
> Michael



  • Prev by Date: Re: atoi equivalents?
  • Next by Date: Correcting a typing blunder
  • Previous by thread: Re: atoi equivalents?
  • Next by thread: Re: atoi equivalents?