[Code Note] upload an ID card number to return a birthday string and an ID card number string

Source: Internet
Author: User

[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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.