• 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: NSScanner isAtEnd
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSScanner isAtEnd


  • Subject: Re: NSScanner isAtEnd
  • From: Jack <email@hidden>
  • Date: Sun, 11 Sep 2005 11:11:40 -0400

>From your description it sounds like you only need to read one single double
from the text field.  There is no need for the while loop, just get rid of
it. Also you could set a formatter on the text field to only accept digits
and simple use the NSString method doubleValue.

double x = [[theTextView string] doubleValue];

------ Otherwise to ignore non-digits do:

NSString *textViewContents = [theTextView string];
double x = 0.0;

NSScanner *doubleScanner = [NSScanner scannerWithString:textViewContents];
[doubleScanner setCharactersToBeSkipped:[[NSCharacterSet
decimalDigitCharacterSet] invertedSet]];
BOOL gotDouble;

gotDouble = [doubleScanner scanDouble:&x];

if (gotDouble) {
    if (5.5 == x) {
        NSLog(@"x was correctly extracted");
    }
    NSLog(@"double extracted: %f", x);
}
else {
        NSLog(@"Double not extracted");
}

Jack Frost
http://www.bruji.com/


 _______________________________________________
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

  • Prev by Date: How to bind this situation?
  • Next by Date: NSApp runModalSession: problem
  • Previous by thread: Re: NSScanner isAtEnd
  • Next by thread: Old NeXT code
  • Index(es):
    • Date
    • Thread