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.