/// <Summary> /// determine men and women by ID card number /// </Summary> /// <Param name = "stridcard"> NULL: cannot be blank. Number of digits: the number of digits is incorrect. Null: program exception </param> Public static string getsexbyidcard (string stridcard) {try {string strsex = ""; // obtain the entered ID number if (string. isnullorempty (stridcard) {// ID card number cannot be blank. If it is empty, return strsex = "blank"; return strsex ;} else {// ID card number can only be 15 or 18 other illegal if (stridcard. length! = 15 & stridcard. length! = 18) {strsex = "digits"; return strsex ;}// string Birthday = ""; string sex = ""; // process the 18-digit ID card number to get the birthday and gender code from the number if (stridcard. length = 18) {// Birthday = stridcard. substring (6, 4) + "-" + stridcard. substring (10, 2) + "-" + stridcard. substring (12, 2); Sex = stridcard. substring (14, 3);} // process the 15-digit ID card number to get the birthday and gender code from the number if (stridcard. length = 15) {// Birthday = "19" + stridcard. substring (6, 2) + "-" + stridcard. substring (8, 2) + "-" + stridcard. substring (10, 2); Sex = stridcard. substring (12, 3);} // textbox_birthday.text = birthday; // If (INT. parse (sex) % 2 = 0) {strsex = "female" ;}else {strsex = "male" ;}return strsex ;}catch {return NULL ;}}
Supports 15-digit and 18-digit ID cards.
Identify men and women using ID card numbers