[Code Note] upload an ID card number to return a birthday string and an ID card number string
Code:
-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. NSString * birthDay = [self birthdayStrFromIdentityCard: @ "134825194401014241"]; NSLog (@ "-- birthDay-% @", birthDay );} // pass the ID card to return the birthday string-(NSString *) birthdayStrFromIdentityCard :( NSString *) numberStr {NSMutableString * result = [NSMutableString stringWithCapacity: 0]; NSString * year = nil; NSString * month = nil; BOOL isA LlNumber = YES; NSString * day = nil; if ([numberStr length] <14) return result; // ** intercept the first 14 NSString * fontNumer = [numberStr substringWithRange: NSMakeRange (0, 13)]; // ** check whether all the first 14 digits are digits; const char * str = [fontNumer UTF8String]; const char * p = str; while (* p! = '\ 0') {if (! (* P> = '0' & * p <= '9') isAllNumber = NO; p ++;} if (! IsAllNumber) return result; year = [numberStr substringWithRange: NSMakeRange (6, 4)]; month = [numberStr substringWithRange: NSMakeRange (10, 2)]; day = [numberStr substringWithRange: NSMakeRange (12, 2)]; [result appendString: year]; [result appendString: @ "-"]; [result appendString: month]; [result appendString: @ "-"]; [result appendString: day]; return result ;}
Output:
13:26:38. 308 pass the ID card number to return the birthDay string [6947: 172533] -- birthDay-1944-01-01