C# 版
function ID15T18(strTemp) { var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); var nTemp = 0, i;
if(strTemp.length==15) { strTemp = strTemp.substr(0,6) + '19' + strTemp.substr(6,strTemp.length-6); for(i = 0; i < strTemp.length; i ++) { nTemp += strTemp.substr(i, 1) * arrInt[i]; } strTemp += arrCh[nTemp % 11]; }
return strTemp; }
VB 版
privatestringConvert15To18(stringstrTemp) { int[]arrInt=newint[]{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; stringarrCh="10X98765432"; intnTemp=0; if(strTemp.Length==15) { strTemp=strTemp.Substring(0,6)+"19"+strTemp.Substring(6,strTemp.Length-6); for(inti=0;i<strTemp.Length;i++) { nTemp+=int.Parse(strTemp.Substring(i,1).ToString())*arrInt[i]; } strTemp+=arrCh[nTemp%11]; } chardd=arrCh[nTemp%11]; returnstrTemp; } |