On Feb 26, 2008, at 9:47 PM, C Sandeep wrote:

Thanks for the ideas. Im using the class method to evaluate such
strings, thusly:

-(NSNumber *) getNumberFrom: (NSString *) str {

   NSScanner *scanner = [NSScanner scannerWithString: str];
   int numerator, denominator;
   [scanner scanInt: &numerator];
   [scanner scanString:@"/" intoString: NULL];
   [scanner scanInt: &denominator];
   float result = (float) numerator/denominator;
   NSNumber *nm = [NSNumber numberWithFloat: result];

   return nm;
}


Unless you have very good control over the input to your function, you should probably add better error checking:

        if ([scanner scanInt: &numerator])
        {
                // Continue parsing
        }

j o a r


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to