• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Converting string equation to int
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Converting string equation to int


  • Subject: Converting string equation to int
  • From: Christopher Drum <email@hidden>
  • Date: Fri, 11 Feb 2005 16:54:04 -0800

Does anyone know a Cocoa method that will accept an equation as an NSString and evaluate it to achieve an int (or long, or whatever). I want to be able to do something like:

NSString *equation = @"7+5";
int x = [equation intValue];
NSLog(@"equation evaluates to: %i", x);


Unfortunately, intValue doesn't seem to look at a string as an evaluatable equation, and I get 7 as the result rather than 12. Cocoa seems to stop as soon as it reaches a non-numeric character.

I feel like there is some easy way to get this to work that I am overlooking. Any ideas?


------------------------------------------------------------------ Christopher Drum http://homepage.mac.com/christopherdrum

Check out FileWrangler, my five-star rated (MacUpdate, VersionTracker) Cocoa app written in Objective-C for the batch renaming of files.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Converting string equation to int
      • From: Sherm Pendley <email@hidden>
    • Re: Converting string equation to int
      • From: Jason Jobe <email@hidden>
  • Prev by Date: Re: Philosophy of FSRef - way
  • Next by Date: enable binding in tableView - was Re: Welcome to the "Cocoa-dev" mailing list
  • Previous by thread: Re: [SOLVED] Disappearing NSButtons
  • Next by thread: Re: Converting string equation to int
  • Index(es):
    • Date
    • Thread