NSScanner isAtEnd
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