Question raised:
In modern society, a person is always inseparable from numbers. People in society always have an ID number, and students studying in school must have a student number, and these numbers are not all meaningless numbers. The program I wrote is used to analyze these numbers and express meaningful meanings.
Programming environment:
VS.NET
implementation technology:
ASP.NET
Key:
The use of String.Substring(Int32,Int32) method, the use of Literal control, and the use of switch statement.
text:
On the Web form, place a Label control, a Literal control, a TextBox control, and a Button control. Set the Text property of the Label control to "Your student number:" and the Visible property of the Literal control to "False". I mainly code the Click() event of the Button control. When the button is clicked, the entered number is analyzed, and then the analyzed content is displayed using a Literal control.
Click() event of Button control:
string studentNo = txtNo.Text; // Assign student number to studentNo string
if (!studentInfo.Visible)
{
studentInfo.Visible = true; // If the Literal control is invisible, display it.
}
try
{
// Get substring operation
string strStartYear = studentNo.Substring(0,2); //Enrollment year
string strTotalYears = studentNo.Substring(2,1); // Schooling system
string strSchool = studentNo.Substring(3,2); // College
string strClass = studentNo.Substring(5,1); // class
string strNumber = studentNo.Substring(6,2); // number
// Match numbers with text
//The content is purely fictitious
switch(strSchool)
{
case "01":
strSchool = "School of Liberal Arts";
break;
case "02":
strSchool = "School of Science";
break;
case "03":
strSchool = "College of Engineering";
break;
case "04":
strSchool = "Technology College";
break;
case "05":
strSchool = "School of Communication and Arts";
break;
case "06":
strSchool = "Business School";
break;
case "07":
strSchool = "Law School";
break;
case "08":
strSchool = "Vocational Education College";
break;
case "09":
strSchool = "College of Construction Engineering";
break;
case "10":
strSchool = "Information School";
break;
default:
strSchool = "There is nothing";
break;
}
studentInfo.Text = "You enrolled in "+strStartYear+" year "+", and the selected major is "+strTotalYears+" year."+
"You are currently studying "+" in the "+strSchool+" college "+strClass+" class, and your number is: "+strNumber+".";
}
catch
{
Response.Write("The substring operation is out of bounds!");
}
finally
{
}
Note: The student number here is 8 digits.
Example:
After the web application is running, enter: 02408122 in the text box. See what the result is? :)
Rendering:
Extensions to the program:
In order to prevent incorrect input, you can add a RegularExpressionValidator and a ValidationSummary control. The regular expression is "d{8}". When the input is not an 8-digit number, an error message will be displayed on the page.
summary:
The analysis of ID number is similar to the analysis of student ID number.
text:
The ID number here is considered to be 18 digits.
Add a Label control, a TextBox control, a Button control, and a Literal control on the page. The Text property of the Label control is set to "ID card number:", and the Literal control will display the information in the ID card number. The key is still in the Click() event of the Button control.
Click() event of Button control:
string strID = txtID.Text;
if (!txtID.Visible)
{
txtID.Visible = true;
}
try
{
string strYear = strID.Substring(6,4); // year
string strMonth = strID.Substring(10,2); // Month
string strDay = strID.Substring(12,2); //
DayLiteral1.Text = "Your birthday is:"+strYear+"year"+strMonth+"month"+strDay+"number";
}
catch
{
Response.Write("The program has an error!");
}
finally
{
}
Display renderings: