谁给一个可以正确的将15位身份证号码转为18位的C#语言写的函数
谁给一个可以正确的将15位身份证号码转为18位的C#语言写的函数啊?
谢谢!
------解决方案--------------------refer:http://www.xker.com/page/e2007/0116/10435.html
------解决方案-------------------- string GetNewIDCard(string IDCard) {
int i = 0;
int S = 0;
string[] Wi = "7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1".Split(",");
string[] Wf = "1,0,X,9,8,7,6,5,4,3,2".Split(",");
if ((IDCard.Substring(6, 2) >= Now.AddYears(-14).Year.Substring(2, 2))) {
IDCard = (IDCard.Substring(0, 6) + ("18" + IDCard.Substring(6, 9)));
}
else {
IDCard = (IDCard.Substring(0, 6) + ("19" + IDCard.Substring(6, 9)));
}
for (i = 0; (i <= 16); i++) {
S = (S
+ (Wi[i] * IDCard.Substring(i, 1)));
}
return (IDCard + Wf[(S % 11)]);
}
------解决方案--------------------此方法亲测有效:
private static string per15To18(string perIDSrc)
{
int iS = 0;
//加权因子常数