• 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: Paolo Bertani <email@hidden>
  • Date: Wed, 3 May 2006 08:25:42 +0200


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


Boyd,
if you need to check that the text entered by the user is an integer value you may try this:


convert the NSString to int, convert the int back to NSString, compare the resulting NSString with the original one. If they are equal then there are no mistakes on the text.

BTW: if the user enters the text on a text field, I would check the input every time a new char is entered, playing a beep if the user types a letter instead of a number.

Paolo.
_______________________________________________
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: NSString intValue
      • From: Bill Bumgarner <email@hidden>
    • Re: NSString intValue
      • From: Ondra Cada <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>)

  • Prev by Date: [Q] C++ object as an Notification observer?
  • Next by Date: Handling Exceptions
  • Previous by thread: Re: NSString intValue
  • Next by thread: Re: NSString intValue
  • Index(es):
    • Date
    • Thread