Re: NSString doubleValue and zero
Re: NSString doubleValue and zero
- Subject: Re: NSString doubleValue and zero
- From: Brian Webster <email@hidden>
- Date: Tue, 18 Feb 2003 16:46:48 -0600
You can use the isAtEnd method of NSScanner to determine whether the
scanner scanned characters all the way to the end of the string. If it
returns NO, that means that there is still some stuff left that wasn't
scanned, so the whole string doesn't represent a number.
On Tuesday, February 18, 2003, at 04:43 PM, olivier wrote:
this works fine except if the string i pass in begin with a number and
ends with some extra character (e.g.: 123abc will return 123 as a
double value) where it states it is a valid number and remove the
character at the end.
Is there a way to change that behavior, so that it reject those.
olivier
On Tuesday, February 18, 2003, at 03:57 PM, Brian Webster wrote:
On Tuesday, February 18, 2003, at 03:30 PM,
email@hidden wrote:
I use the message doubleValue to get a number value out of a string.
If
the string is not a number then i need to store the string. My
problem
is that if the string is not a number then doubleValue return 0.
But then how am i supposed to know when it is an actual number with
value 0 or a string that was not a number.
Any pointers appreciated
Take a look at NSScanner's scanDouble: method. Create a new scanner
for your string and use it to scan for your double, and it will
return you a BOOL saying whether it successfully scanned a number.
If it returns NO, you can just keep the string, otherwise keep the
number.
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.