• 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
Re: NSString intValue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString intValue


  • Subject: Re: NSString intValue
  • From: Boyd Collier <email@hidden>
  • Date: Thu, 4 May 2006 12:16:47 -0700

Thanks to everyone who offered suggestions. As I remarked in an earlier posting, I had already tried NSScanner's scanInt: and the problem with it was that if a user enters, for example, 5X, it returns 5 and doesn't signal a problem. However, using isAtEnd: can indeed be used to deal with this problem, so my code now reads

int myInt;
NSScanner *theScanner = [NSScanner scannerWithString:theString];
if ([theScanner scanInt:&myInt] && [theScanner isAtEnd] )
	NSLog(@"The int represented by the string = %i", myInt); // for testing
else
	NSLog(@"The string didn't represent an int"); 		// for testing


Incidentally, trying to simplify the above by using
NSScanner *theScanner = [NSScanner scannerWithString:[theTextField stringValue]];
doesn't give the desired results. (I mention this for other newbies who might be tempted to try it.)


Using NSNumberFormatter, which was suggested by several persons, may be a preferable way to do what I want to do, and I'll certainly study the documentation of this. However, for the time being, it looks more complicated than the above, especially considering what the docs say about changes made in 10.4.

Thanks again, Boyd
_______________________________________________
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


References: 
 >NSString intValue (From: Boyd Collier <email@hidden>)
 >Re: NSString intValue (From: glenn andreas <email@hidden>)
 >Re: NSString intValue (From: Boyd Collier <email@hidden>)
 >Re: NSString intValue (From: "Shawn Erickson" <email@hidden>)

  • Prev by Date: NSTextView setNeedsDisplayInRect:avoidAdditionalLayout:
  • Next by Date: Re: Hiding find panel in NSTextView
  • Previous by thread: Re: NSString intValue
  • Next by thread: Re: NSString intValue
  • Index(es):
    • Date
    • Thread