One, code.
-(void) viewdidload
{
[super viewdidload];
Do no additional setup after loading the view.
NSString *sex=[self sexstrfromidentitycard:@ "139876456767892345"];
NSLog (@ "--sex--%@", Sex);
}
Returned by the ID number to gender
-(NSString *) Sexstrfromidentitycard: (NSString *) numberstr{
nsstring *result = nil;
BOOL isallnumber = YES;
if ([Numberstr length]<17) return result
;
* * Interception 17th for gender identifier
nsstring *fontnumer = [Numberstr substringwithrange:nsmakerange (1)];
* * Whether the test is a number;
const char *STR = [Fontnumer utf8string];
const char *p = str;
while (*p!= ' ") {
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;
}
Second, output.
2015-10-22 10:33:38.518 by ID number return sex [2356:74542]--sex--Female
The above is a small set up to introduce the development of iOS by the ID card number of the realization of gender code, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!