Possible Duplicate:
iPhone how to check that a string is numeric only
I am trying to look up some basic functionality in Objective C, but can't seem to locate the basic answer.
What I really need is to check
if ( some_string is numeric )
{
}
I would assume there would just be some built in function for that. No?
I am looking at this StackOverflow question How to check if NSString is numeric or not and they seem to be doing things the very complicated way.
Isn't there some basic check I can do in one simple line?
Thanks!
Isn't there some basic check I can do in one simple line?
No.
NSScanner *scanner = [NSScanner scannerWithString:testString];
BOOL isNumeric = [scanner scanInteger:NULL] && [scanner isAtEnd];
If you want to allow decimal digits exchange scanInteger:
by scanDouble:
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With