Advertisement
monaliza86

Untitled

Jan 27th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Windows.Forms;
  5.  
  6. namespace StringHandling
  7. {
  8.     public partial class Form1 : Form
  9.     {
  10.         public Form1()
  11.         {
  12.             InitializeComponent();
  13.         }
  14.  
  15.         private void btnExit_Click(object sender, EventArgs e)
  16.         {
  17.             this.Close();
  18.         }
  19.  
  20.         private void btnParse_Click(object sender, EventArgs e)
  21.         {
  22.             string fullEmail = txtEmail.Text.Trim();
  23.  
  24.             if (fullEmail.Contains('@'))
  25.             {
  26.                 string[] emails = fullEmail.Split('@');
  27.                 string userName = emails[0];
  28.                 string domain = emails[1];
  29.                 MessageBox.Show("User name: " + userName + "\n\n" + "Domain name: " + domain.Trim(), "Parsed String");
  30.             }
  31.             else
  32.             {
  33.                 MessageBox.Show("Please enter a valid email address", "Invalid input");
  34.             }
  35.         }
  36.  
  37.         private void txtEmail_TextChanged(object sender, EventArgs e)
  38.         {
  39.         }
  40.  
  41.         private void btnFormat_Click(object sender, EventArgs e)
  42.         {
  43.             if (IsValidData())
  44.  
  45.             {
  46.                 StringBuilder full_Address = new StringBuilder("City, State, Zip: ");
  47.                 string city = txtCity.Text.Trim();
  48.                 string state = txtState.Text.Trim().ToUpper();
  49.                 string zipCode = txtZipCode.Text.Trim().ToUpper();
  50.                 string firstLetter = city.Substring(0, 1).ToUpper();
  51.                 string otherLetters = city.Substring(1).ToLower();
  52.                 city = firstLetter + otherLetters;
  53.                 full_Address.Insert(full_Address.Length, city + " ," + state + " " + zipCode);
  54.  
  55.                 MessageBox.Show(full_Address.ToString(), "Formated Address");
  56.             }
  57.         }
  58.  
  59.         private bool IsPresent(TextBox tb, string name)
  60.         {
  61.             if (tb.Text == "")
  62.             {
  63.                 MessageBox.Show(name + " is a required field");
  64.                 return false;
  65.             }
  66.  
  67.             return true;
  68.         }
  69.  
  70.         private bool IsValidData()
  71.         {
  72.             return
  73.  
  74.                 IsPresent(txtCity, "City") &&
  75.                 IsPresent(txtState, "State") &&
  76.                 IsPresent(txtZipCode, "Zip Code");
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement