This code is supposed to parse an email into the username and domain name. If I type in apa@gmail.com, a message box displays and says "Username: apa Domain Name: gmail.com".
I adapted the code from my textbook and keep getting the above error message at email = Email.Remove(0, 1);
and domainName = Email.Remove(Email.Length -1, 1)
. Any suggestions?
public partial class StringHandling : Form
{
string email = "";
string state = "";
string city = "";
int zipCode = 0;
public StringHandling()
{
InitializeComponent();
}
private void btnParse_Click(object sender, EventArgs e)
{
string Email = "";
string domainName = "";
email = txtEmail.Text;
email = Email.Trim();
if (email.StartsWith(""))
email = Email.Remove(0, 1);
if (email.EndsWith("@"))
domainName = Email.Remove(Email.Length - 1, 1);
MessageBox.Show("Username: " + email + "\n" + "Domain Name: " + domainName);