RosettaCodeData/Task/Determine-if-a-string-is-numeric/Objective-C/determine-if-a-string-is-numeric-1.m

11 lines
386 B
Mathematica
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
if( [[NSScanner scannerWithString:@"-123.4e5"] scanFloat:NULL] )
NSLog( @"\"-123.4e5\" is numeric" );
else
NSLog( @"\"-123.4e5\" is not numeric" );
if( [[NSScanner scannerWithString:@"Not a number"] scanFloat:NULL] )
NSLog( @"\"Not a number\" is numeric" );
else
NSLog( @"\"Not a number\" is not numeric" );
// prints: "-123.4e5" is numeric
// prints: "Not a number" is not numeric