Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

eval() works correctly on Android not on Iphone


I face a strange problem.
This works on Android NOT on Iphone:

result = String(eval(HTValue));
HTLabel.text = result;

where HTValue = '12+3' for example.

But this works on Android AND Iphone :

result = String(eval('12+3'));
HTLabel.text = result;

Did I miss something ?
Thanks for your help.

— asked May 16th 2010 by Stephane Boyeau
  • android
  • eval
  • iphone

1 Answer

  • I found a solution. But don't understand why it works.
    Here is what I've found :

    To make it work under Iphone + Android, just add a semicolon to the eval string like this :

    result = String(eval('12+3;'));
    HTLabel.text = result;
    — answered May 17th 2010 by Stephane Boyeau
    1 Comment
    • Had the same problem, perfect solution. It seems using the semicolon is actually the proper way to do it, only Android accepts it without the semicolon as well…

      — commented August 10th 2010 by Friedrich Seydel
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.