IOS returns gender from ID card number, ios ID card number gender
This blog post from: http://www.cnblogs.com/yang-guang-girl/p/5683454.html
-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. NSString * sex = [self sexStrFromIdentityCard: @ "139876456767892345"]; NSLog (@ "-- sex -- % @", sex );} // gender returned by the ID card number-(NSString *) sexStrFromIdentityCard :( NSString *) numberStr {NSString * result = nil; BOOL isAllNumber = YES; if ([numberStr length] <17) return result; // ** returns the NSString * fontNumer = [numberStr substr IngWithRange: NSMakeRange (16, 1)]; // ** check whether it is a number; const char * str = [fontNumer UTF8String]; const char * p = str; while (* p! = '\ 0') {if (! (* P> = '0' & * p <= '9') isAllNumber = NO; p ++;} if (! IsAllNumber) return result; int sexNumber = [fontNumer integerValue]; if (sexNumber % 2 = 1) result = @ "male"; // result = @ "M "; else if (sexNumber % 2 = 0) result = @ "female"; // result = @ "F"; return result ;}
Output
10:33:38. 518 the Gender returned by the ID card number [2356: 74542] -- sex -- female