Use C # To upgrade the ID card number from 15 digits to 18 digits!

Source: Internet
Author: User
1 Using System;
2 Using System. collections;
3
4 Public   Class Myclass
5 {
6 Public   Static   Void Main ()
7 {
8Console. writeline (per15to18 ("429005811009091"));
9RL ();
10}
11
12 Public   Static   String Per15to18 ( String Peridsrc)
13 {
14 Int Is =   0 ;
15  
16 // Weighting Factor constant
17 Int [] IW = New   Int [] { 7 , 9 , 10 , 5 , 8 , 4 , 2 , 1 , 6 , 3 , 7 , 9 , 10 , 5 , 8 , 4 , 2 } ;
18 // Verification Code constant
19 String Lastcode = " 10x98765432 " ;
20 // New ID card number
21 String Peridnew;
22  
23 Peridnew = Peridsrc. substring ( 0 , 6 );
24 // Fill in the numbers '1' and '9' on the 6th and 7th digits.
25 Peridnew + =   " 19 " ;
26  
27 Peridnew + = Peridsrc. substring ( 6 , 9 );
28  
29 // Weighted sum
30 For ( Int I = 0 ; I < 17 ; I ++ )
31 {
32Is+ = Int. Parse (peridnew. substring (I,1))*IW [I];
33}  
34
35 // Modulo operation to obtain the modulo Value
36 Int Iy = Is % 11 ;
37 // Obtain the modulo index number from lastcode and add it to the last digit of the ID card, that is, the new ID card number.
38 Peridnew + = Lastcode. substring (Iy, 1 );
39
40 Return Peridnew;
41 }  
42
43
44
45
46 Helper Methods # Region Helper Methods
47
48 Private   Static   Void WL ( Object Text, Params   Object [] ARGs)
49 {
50Console. writeline (text. tostring (), argS );
51}
52
53 Private   Static   Void RL ()
54 {
55Console. Readline ();
56}
57
58 Private   Static   Void Break ()
59 {
60System. Diagnostics. Debugger. Break ();
61}
62
63 # Endregion
64 }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.