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