Re: NSString intValue
Re: NSString intValue
- Subject: Re: NSString intValue
- From: Boyd Collier <email@hidden>
- Date: Tue, 2 May 2006 15:23:02 -0700
Thanks for the quick reply. I had already tried NSScanner's scanInt:
and the problem with it is that if a user enters, for example, 5X, it
returns 5 and doesn't signal a problem. However, your suggestion
prompted me to look more closely at other NSScanner methods, and I
found isAtEnd: So it appears that I can use this to identify
situations in which the user has some characters that can't represent
an integer following those that can.
Boyd
On May 2, 2006, at 2:04 PM, glenn andreas wrote:
On May 2, 2006, at 4:01 PM, Boyd Collier wrote:
Apple's documentation of the method intValue reads as follows:
The integer value of the receiver’s text, assuming a decimal
representation and skipping whitespace at the beginning of the
string. Returns INT_MAX or INT_MIN on overflow. Returns 0 if the
receiver doesn’t begin with a valid decimal text representation
of a number.
Thus, the string @"0" returns 0, which for my purposes is
acceptable, but a string such as @"X" also returns 0, which isn't
acceptable. Is there an easy way to distinguish between these two
situations, or do I have to write a bunch of extra code to
distinguish between them?
Use NSScanner's scanInt:
Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
Widgetarium | the quickest path to widgets
_______________________________________________
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