Code:
- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.NSString*birthday=[self Birthdaystrfromidentitycard:@"134825194401014241"]; NSLog (@"--birthday-%@", BirthDay);}#pragma-mark-functions//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; }
Pass the ID number back to the birthday string