C # Production of the number Mask program

Source: Internet
Author: User
Tags foreach

Today, the major media are fashionable to participate in the activities through text messages and winning the behavior, the winning numbers are mostly used ' * ' to cover up the middle of their mobile number such as: 138*****345, today, we do is to use a class library to implement this common function, in order to reference in the site and program.

Text: Below, let's start, first of all, with vs2005 to build a C # class library, we named Nummask, his Class1 renamed as Easy to remember other names, I renamed Masker, and then we add the following code:

Nummask

Using System;
Using System.Collections.Generic;
Using System.Text;
Using System.Collections;

Namespace Nummask
{public
    class masker
    {
        ArrayList numbers = new ArrayList ();//define a ArrayList variable, Used to collect numbers passed from the main program
        ArrayList newnum = new ArrayList ();//This is a ArrayList public ArrayList numberchange that returns the processing result
        ( ArrayList number)
        {
            foreach (string num in number)
            {
                numbers. Add (num);//Send received number into numbers
            }
            foreach (string n in numbers)//handle
            {
                char[] temp = N.tochararray ( );
                for (int i = 3; I <= 7; i++)//Replace the number 3 to 7 digits with the * number, there should be a better way, my more stupid, I hope you can give me advice
                {
                    temp[i] = ' * ';
                }
                string s = new string (temp);
                Newnum. Add (s);//Put the mask number into the result array waiting to return the Newnum}}

Then generate it and get the NumMask.dll file

Create a WinForm project and add just the NumMask.dll as a reference. The WinForm interface is as follows:

Instead of using a database as a number source, we use a simple, well-defined number, which in practice can be read to a ArrayList in a database and then invoked nummask to handle it.

ListBox1 is used to display the processing results, let's look at the code for the "Start Conversion" button: Remember to add a using nummask at the beginning;

Button1

private void Button1_Click (object sender, EventArgs e)
        {
            ArrayList al = new ArrayList ();//define Al as the original number array
            ArrayList ab = new ArrayList ();//define AB as the processed result
            al. Add ("13888567890");//Adds number to the original number
            al. ADD ("15878990987");
            Nummask.masker mk = new masker ();//Instantiate a masker
            ab=mk. Numberchange (AL); into which the original data Al is received, with AB receive the result
            foreach (string nums in ab)
            {
                listBox1.Items.Add (nums);//output result
            }
        }

After compiling, you can see the effect of the following diagram:

Summary: This class library still has a lot of places to be reformed, such as judging the validity of data and so on, please give a lot of opinions and suggestions, help me better study and progress.

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.