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

NSScanner isAtEnd


  • Subject: NSScanner isAtEnd
  • From: Boyd Collier <email@hidden>
  • Date: Sat, 10 Sep 2005 17:14:26 -0700

Hi,
Below is a snippet of code I wrote to learn how to get numbers from text typed by the user into a document window. If (as a test) I type in 5.5 and hit a button in the window, the code shown below is executed and *xptr does indeed equal 5.5. However, if I type in some miscellaneous characters that can't represent a number, then [doubleScanner isAtEnd] never seems to return false, so, without testing gotDouble, the while loop is not exited. I seem not to understand the isAtEnd method, which I thought would return false at the end of the string that was used to init the scanner. Where am I screwing up?


Thanks, Boyd


NSString *textViewContents = [[theTextView string] copy];

    double x;
    double *xptr;
    xptr = &x;

NSScanner *doubleScanner;
doubleScanner = [[NSScanner alloc] initWithString:textViewContents];
BOOL gotDouble;


    while( ![doubleScanner isAtEnd] )
    {
        gotDouble = [doubleScanner scanDouble:xptr];
        if (5.5 == *xptr) {
            NSLog(@"x was correctly extracted");
        }
        else if ( !gotDouble) {
            break;
        }
    }

_______________________________________________
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: NSScanner isAtEnd
      • From: Andreas Mayer <email@hidden>
  • Prev by Date: _newFirstResponderAfterResigining
  • Next by Date: Re: [ANN] HOM paper available
  • Previous by thread: Re: _newFirstResponderAfterResigining
  • Next by thread: Re: NSScanner isAtEnd
  • Index(es):
    • Date
    • Thread