Code:
- (void) viewdidload{[Super Viewdidload]; //Do any additional setup after loading the view.NSString*birthday=[self Birthdaystrfromidentitycard:@"134825194401014241"]; NSLog (@"--birthday-%@", BirthDay); }//Pass ID to return birthday string-(NSString *) Birthdaystrfromidentitycard: (NSString *) numberstr{nsmutablestring*result = [nsmutablestring stringwithcapacity:0]; NSString*year =Nil; NSString*month =Nil; BOOL Isallnumber=YES; NSString*day =Nil; if([Numberstr length]< -) returnresult; //* * Interception of the first 14 digitsNSString *fontnumer = [Numberstr substringwithrange:nsmakerange (0, -)]; //* * 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)returnresult; year= [Numberstr Substringwithrange:nsmakerange (6,4)]; Month= [Numberstr Substringwithrange:nsmakerange (Ten,2)]; Day= [Numberstr Substringwithrange:nsmakerange ( A,2)]; [Result Appendstring:year]; [Result appendString:@"-"]; [Result Appendstring:month]; [Result appendString:@"-"]; [Result Appendstring:day]; returnresult; }
Output:
2014-12-02 11:51:24.089 Pass the ID number to return the birthday string [7594:60b]--birthday-1944-01-01
Pass the ID number to return the birthday string