Code:
-(void) viewdidload{[Super Viewdidload]; Do any additional setup after loading the view. NSString *birthday=[self birthdaystrfromidentitycard:@ "134825194401014241"]; NSLog (@ "--birthday-%@", BirthDay); }//identity card return birthday string-(NSString *) Birthdaystrfromidentitycard: (NSString *) numberstr{nsmutablestring *result = [NSMutableS Tring stringwithcapacity:0]; NSString *year = nil; NSString *month = nil; BOOL isallnumber = YES; NSString *day = nil; if ([Numberstr length]<14) return result; * * Intercept the first 14 bits nsstring *fontnumer = [Numberstr substringwithrange:nsmakerange (0, 13)]; * * The first 14 digits of the test are all numbers; const char *STR = [Fontnumer utf8string]; const char *p = str; while (*p!= ') {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:
2015-10-13 13:26:38.308 ID Number can return birthday string [6947:172533]--birthday-1944-01-01
"Code Note" Pass the ID number to return the birthday string