class or instance method for checking string is valid integer?
+2
A:
You can use NSScanner for that. NSString itself also has -doubleValue and -intValue methods.
Vladimir
2009-10-12 10:18:42
I'd say that NSScanner would be the preferred way, as -scanDouble: returns YES or NO depending on whether the string has a valid floating point number within it or not.
Brad Larson
2009-10-12 12:41:10
A:
If you're looking at the ENTIRE string, rather than just a portion, you could just use -intValue or -doubleValue. If it returns non-zero, it's valid.
Ben Gottlieb
2009-10-12 10:41:50
But what if the string is actually "0" or "0.0"? Admittedly, checking for a non-zero number can be good enough for many cases.
Brad Larson
2009-10-12 12:39:35