First, thanks to everyone who suggested ways to handle this. Next, an admission of guilt for faulty memory; mine, not my Mac's: in poking around, I discovered that I'd asked pretty much the same question (for ints) nearly 2 years ago and had gotten similar answers. My apologies.

I've decided to use a scanner, and, as a couple of you said, it's really rather simple. But I was concerned about whether using something like

        [[NSScanner scannerWithString:aString] scanDouble:&distance];

when, in some situations, I will be scanning for potentially thousands of values within a loop, and so I presumed that this would cause an equal number of scanners to accumulate in the default autorelease pool. Is that correct? So I tried

        NSScanner *tempScanner = [[NSScanner alloc] initWithString:aString];
        [tempScanner scanDouble:&distance];
        [tempScanner release];

in a loop, wondering if all the allocations and releases would slow things down. The result was that scanning for 10000 values took only about 8 milliseconds on my 2.8 GHz iMac, which is plenty fast enough for my purposes.

Any further comments, even ones telling me that I should take up knitting instead of programming, are welcome.

Boyd


On Mar 20, 2008, at 4:13 PM, Boyd Collier wrote:

According to Apple's documents, the selector doubleValue returns 0.0 if the instance of an NSString that is the receiver "doesn’t begin with a valid text representation of a floating-point number." Is there a simple way to distinguish between the string 0.0, which shouldn't be considered illegitimate for my purposes, and the string (for example) X0.0 other than writing extra lines of code to distinguish one case from the other? I know I could use a scanner, but perhaps there's something simple that I'm overlooking.

Boyd_______________________________________________

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/bcollier%40sunstroke.sdsu.edu

This email sent to [EMAIL PROTECTED]




_______________________________________________

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