how can I check if the NSString *val I have has a Integer or float ?? The raw approach is to look for "." character..but is there a more graceful way to do this?
First, try [NSScanner scanInt:]&& [NSScanner isAtEnd]. If it returns YES, then you have an int. scanInt will scan forward as long as it can interpret the stream as an int. If isAtEnd is YES, then the entire string could be interpreted as an int (so you have an int).
Otherwise, try [NSScanner scanDouble:]. If it returns YES, then you have a double.
If both return NO, then you don't have either.
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