This is the code I have so far: using System; using System.Collections.Generic;
ID: 3605253 • Letter: T
Question
This is the code I have so far:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Lab9_200_Melissa_Thoma
{
public partial class Lab9 : Form
{
public Lab9()
{
InitializeComponent();
}
private void Lab9_Load(object sender, EventArgs e)
{
}
private void btnFormat_Click(object sender, EventArgs e)
{
string city = "";
string state = "";
string zipcode = "";
city = txtCity.Text;
state = txtState.Text;
zipcode = txtZip.Text;
MessageBox.Show("City, State ,Zip" + city + "," + state + " " + zipcode, "Formatted string");
}
private void btnExit_Click(object sender, EventArgs e)
{
Lab9.ActiveForm.Close();
}
private void btnParse_Click(object sender, EventArgs e)
{
string emailStr = "";
emailStr = txtEmail.Text;
//check if email is valid
if (!emailStr.Contains("@"))
{
MessageBox.Show("The email address must contain an @ sign.", "Entry Error ");
txtEmail.Focus();
}
else
{
string name = "";
string domain = "";
//index of the @ symbol
int indexPos = emailStr.IndexOf("@");
//get name using substring
name = emailStr.Substring(0, indexPos);
//get domain using substring
domain = emailStr.Substring(indexPos + 1, emailStr.Length - 1 - indexPos);
MessageBox.Show("Name : " + name + " Domain name : " + domain, "Parsed string");
}
}
}
Explanation / Answer
namespace Lab9_200_Melissa_Thoma
{
public partial class Lab9 : Form
{
public Lab9()
{
InitializeComponent();
}
private void Lab9_Load(object sender, EventArgs e)
{
}
private void btnFormat_Click(object sender, EventArgs e)
{
string city = "";
string state = "";
string zipcode = "";
city = txtCity.Text;
state = txtState.Text;
zipcode = txtZip.Text;
MessageBox.Show("City, State ,Zip" + city + "," + state + " " + zipcode, "Formatted string");
}
private void btnExit_Click(object sender, EventArgs e)
{
Lab9.ActiveForm.Close();
}
private void btnParse_Click(object sender, EventArgs e)
{
string emailStr = "";
emailStr = txtEmail.Text;
//check if email is valid
if (!emailStr.Contains("@"))
{
MessageBox.Show("The email address must contain an @ sign.", "Entry Error ");
txtEmail.Focus();
}
else
{
string name = "";
string domain = "";
//index of the @ symbol
int indexPos = emailStr.IndexOf("@");
//get name using substring
name = emailStr.Substring(0, indexPos);
//get domain using substring
domain = emailStr.Substring(indexPos + 1, emailStr.Length - 1 - indexPos);
MessageBox.Show("Name : " + name + " Domain name : " + domain, "Parsed string");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.