- What are the the regular expression symbols for the following?
- Digit: \d
- Word character (letter or digit): \w
- Or: | (vertical line)
- Any character: . (dot)
- One or more occurrences: + (plus)
- Zero or more occurrences: * (star)(
- Zero or one occurrences: ? (question mark)
- Write regular expressions to validate the following:
- An employee ID code begins with the letter E or F, followed by
3 digits, then a dash and 5 more digits.
Ans: (E|F)\d{3}-\d{5} or [EF]\d{3}-\d{5}
- An employee ID code begins with the letter E or F, followed by
3 digits, then a dash and 5 more digits, then, optionally a
dash, a letter, and a number.
[EF]\d{3}-\d{5}([A-Za-z]\d)?
- An integer with leading or trailing zeros trimmed.
Ans: [1-9]([0-9])*
- A telephone number. Example: (312)728-5487
Ans: \(\d{3})\)\d{3}-\d{4}
- What is the difference between the Session collection and
the Application collection?
Ans: Values added to the Session collection persists across postbacks,
but is restricted to a single browser. The Application collection
also persists across postbacks, but can be changed by any browser running
the application.
- Write an application that initializes an int array and
a string array, then writes the contents of these arrays to
the file c:/Database/output.txt.
public void Page_Load(object sender, EventArgs e)
{
int[ ] a = {3, 5, 7, 9};
string[ ] b = {one, two, three, four};
StreamWriter sw = new StreamWriter(c:/Database/output.txt);
for(int i = 0; i <= 3; i++)
{
sr.WriteLine(a[i]);
}
for(int i = 0; i <= 3; i++)
{
sr.WriteLine(b[i]);
}
}
- The file c:/Database/ints.txt contains 10 ints, one in each
row. The file c:/Database.strings.txt contains 10 strings, one
in each row. Display the ints and strings in a Literal control,
one int and string per line.
public void Page_Load(object sender, EventArgs e)
{
litDisplay.Text = ;
StreamWriter sw1 = new StreamWriter(c:/Database/ints.txt);
StreamWriter sw2 = new StreamWriter(c:/Database/strings.txt);
while(sw1.Peek( ) > -1)
{
litDisplay.Text += sw1.ReadLine( ) + +
sw2.ReadLine( ) + <br />;
}
}
- Repeat the previous problem, but double space the lines.
Ans: Change the body of the while loop to this:
litDisplay.Text += <p> + sw1.ReadLine( ) + +
sw2.ReadLine( ) + </p>;
- Repeat Problem 7, but put the ints and strings in a table.
Ans: Change the while loop to this:
litDisplay.Text += <table>;
while(sw1.Peek( ) > -1)
{
litDisplay.Text += <tr><td> + sw1.ReadLine( ) + </td> +
<td> + sw2.ReadLine( ) + </td></tr>;
}
litDisplay.text += </table>;
- Use Visual Studio to create a .css external style page that
sets the background color to beige, body and td font to Verdana,
body color to navy, and td color to maroon. Be sure to attach the
style file to the web page.
Ans: Use this style page:
body { background-color:beige; color:navy; font-family: Verdana; }
td { color: maroon; font-family: Verdana; }